r-wasm / webr

The statistical language R compiled to WebAssembly via Emscripten, for use in web browsers and Node.

Home Page:https://docs.r-wasm.org/webr/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reading a CSV with data.table::read fails claiming the file is empty

MaybeJustJames opened this issue · comments

Here is a reproduction:

webr::install("data.table")
chisq <- data.frame(A = c(1, 0.5, 0.2),
                    B = c(0.1, 0.2, 0.3),
                    C = c(0.54, 0.1, 0.05))
print(chisq)
data.table::fwrite(chisq, file = "chisq.csv", col.names=FALSE)
readLines("chisq.csv")
data.table::fread("chisq.csv")

I expect to read the CSV with data.table::fread. On desktop I get this output:

$ $ Rscript reprod.R 
    A   B    C
1 1.0 0.1 0.54
2 0.5 0.2 0.10
3 0.2 0.3 0.05
[1] "1,0.1,0.54"   "0.5,0.2,0.1"  "0.2,0.3,0.05"
      V1    V2    V3
   <num> <num> <num>
1:   1.0   0.1  0.54
2:   0.5   0.2  0.10
3:   0.2   0.3  0.05

In WebR I get this output:

[1] "test"
    A   B    C
1 1.0 0.1 0.54
2 0.5 0.2 0.10
3 0.2 0.3 0.05
[1] "1,0.1,0.54"   "0.5,0.2,0.1"  "0.2,0.3,0.05"
Error: File is empty: chisq.csv

This looks like a potential culprit?

This is related to Rdatatable/data.table#5969

I tested a new build of the package on a pre-release version of webR 0.3.0 and it is working there:

Screenshot 2024-03-20 at 13 49 26

So I am confident that once webR 0.3.0 is released and the default webR package repo is updated, the problem should go away. Unfortunately, the package repo is frozen in preparation for release, so I will leave this issue open until then.