2

I am trying to covert an *.rds file in R into a *.feather file for use in Python.

library(feather)
data = readRDS("file.rds")
write_feather(data,"file.feather")

However, I receive the following error:

> write_feather(data,"file.feather")
Error: `x` must be a data frame

How can I turn the *.rds file/matrix into a *.feather file to read with Pandas (or any other Pandas-compatible file that can handle a 24000*24000 matrix)?

enter image description here

Stücke
  • 868
  • 3
  • 14
  • 41
  • It appears that your data is not in data.frame format. Try `as.data.frame(as.matrix(data))`. – tacoman Jan 21 '22 at 13:24
  • This seems to have worked and should be an answer! :) At least there was an export. I am trying the import now. – Stücke Jan 21 '22 at 14:08

2 Answers2

2

Coerce matrix obeject to data.frame object:

library(feather)
data = readRDS("file.rds")
as.data.frame(as.matrix(data))
write_feather(data,"file.feather")
tacoman
  • 882
  • 6
  • 10
  • Thank you! It worked. I had to run `pip install pyarrow` before the import in Python via `pd.read_feather("file.feather")` but that was of course not a problem! – Stücke Jan 21 '22 at 14:14
1

It's very simple in fact, you can convert only dataframes and you have to name your file: Use:

data = data.frame(data)

Now use the function and it should work:

write_feather(data,"file.feather")
Freynes
  • 21
  • 5
  • Thank you for your answer. It does not work unfortunately. `data = data.frame(data)` returns `Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class ‘structure("dgeMatrix", package = "Matrix")’ to a data.frame`. – Stücke Jan 21 '22 at 13:55