# Error exporting dataframe from Julia to R with CSV.write

**URL:** <https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [June 26, 2019, 2:33pm UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723 "2019-06-26T14:33:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [June 26, 2019, 2:33pm UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723/1 "2019-06-26T14:33:55Z")

</div>

Dear all,  
I prepared an emtpy dataframe in Julia (I am working with Atom) with

```julia
res_df = DataFrame(
    Col_1 = String[],
    Col_2 = UInt8[],
    Col_3 = Float16[])

```

then I populated it and I saved it with

```julia
CSV.write("df.tsv", res_df; delim='\t', append=false)

```

It works and I can open it with Julia. However, I need to open the file with R:

```julia
o_df <- read.table(
  "df.tsv",
  header = TRUE,
  row.names = NULL, 
  dec = ".",
  sep = "\t",
  fill = TRUE,
  stringsAsFactors = FALSE,
  comment.char = ""
)

```

The object is created but one or more of the line must have some problems with the delimiters or the quotations because I can’t visualize the object and R actually crashes. I have seen on the internet that there is an issue with atom/julia and R.

Is there a save way to export dataframes from Julia to R?  
Thank you

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [June 26, 2019, 3:32pm UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723/2 "2019-06-26T15:32:51Z")

</div>

That seems odd that R crashes trying to read a csv file. Can you share the output of your `df.tsv` file once it’s written out? It should be pretty quick to identify if there are any issues.

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [June 26, 2019, 4:01pm UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723/3 "2019-06-26T16:01:07Z")

</div>

Hi, did you try fread from the data.table package in R?  
Another way to exchange dataframes between Julia and R would be feather.

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [June 27, 2019, 6:53am UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723/4 "2019-06-27T06:53:13Z")

</div>

As I said, R loads the object without showing error messages, but when I try to call it, it takes several second if not minutes to show the output. This is essentially empty space. I can’t show it because, as I am using Rstudio, it becomes unresponsive and I need to kill it. Besides, it is not Atom per se that makes this error, since it persists even if a run the julia script in batch mode directly from the shell.

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [June 27, 2019, 6:55am UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723/5 "2019-06-27T06:55:50Z")

</div>

No, the only way I know to save data is CSV.write (for dataframes) and writedlm (for arrays). Do you have more info? I can see that feather creates a binary version of a dataframe. which is good for storage; but a tsv can be accessed with a spreadsheet and checked/modified directly. There is also RCall. Which one would be the simples method? why there might be an issue simply using CSV.write? Tx

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [June 27, 2019, 10:34am UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723/6 "2019-06-27T10:34:17Z")

</div>

Using CSVs to exchange data is always a bit problematic. E.g., encoding issues, precision limitations, and espacing are some of the problems you might encounter.  
I would always prefer using something like feather to move data between two plattforms in a sane way.  
Anyway, if you want to use CSVs for that, it would be much easier to help you, if you post the csv which causes the trouble as quinnj already pointed out.  
For instance trying

```julia
using CSV, DataFrames
res_df = DataFrame(
    Col_1 = String[],
    Col_2 = UInt8[],
    Col_3 = Float16[])
push!(res_df, ("test", 5, 4.3))
CSV.write("df.tsv", res_df; delim='\t', append=false)

```

yields a file which can be read by R using your code without problems.

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [June 27, 2019, 11:13am UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723/7 "2019-06-27T11:13:15Z")

</div>

> [@Rudi79](#):
>
> ```julia
> CSV.write("df.tsv", res_df; delim='\t', append=false)
> 
> ```

is what i used to export the file. I would have attached the file, but how can I? there is not attach button…

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [June 27, 2019, 1:44pm UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723/8 "2019-06-27T13:44:57Z")

</div>

Hmmmm, you could upload it somewhere publicly available (dropbox, google drive, I’ve used [http://ge.tt/](http://ge.tt/) before) and share the link. Or feel free to email me directly (email on my github profile: [https://github.com/quinnj](https://github.com/quinnj)).

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [June 27, 2019, 2:17pm UTC](https://discourse.julialang.org/t/error-exporting-dataframe-from-julia-to-r-with-csv-write/25723/9 "2019-06-27T14:17:51Z")

</div>

Thank you, I’ll do the last since looks the easiest.
