Error exporting dataframe from Julia to R with CSV.write

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

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

then I populated it and I saved it with

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:

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

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.

1 Like

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

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.

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

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

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.

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

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

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