-3

This question has been asked several times, but I haven't found a solution. I have an rda R file (df) that I want to save as a non binary file (such as txt or csv) so I can use it in a text editor program...

Is there a way to do this?

Right now using write.csv(df, file=out.csv) or even, saveRDS(df, file=out.rds) gives me an empty file.

What am I missing here....

EDIT: I'm working with an rda file not an rds file as stated originally

zx8754
  • 52,746
  • 12
  • 114
  • 209
joeblow
  • 13
  • 6
  • write.csv is the way to do this, so without more information, it's going to be very difficult for us to help you. See https://stackoverflow.com/help/mcve and https://stackoverflow.com/q/5963269/210673 for information on how to improve your question so we can better help. – Aaron left Stack Overflow May 23 '17 at 16:10
  • 1
    Without a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) it is a bit hard to tell what is going wrong. – Jaap May 23 '17 at 16:11
  • Actually - there is a typo in my question... I'm working with an rda file... not an rds. – joeblow May 23 '17 at 16:12
  • The input file is irrelevant once you've loaded it into R, so what is `df`? If it's a data.frame, the first option (with quotes on the path) should work, e.g. `write.csv(mtcars, '~/Desktop/mtcars.csv')`. – alistaire May 23 '17 at 16:29
  • Thats just to refer to my data... it is an object right now with a "character" class. I want to save into a data frame so I can use it with other programs. It isn't one now. And write.csv does not work, even following your suggestions with quotes. – joeblow May 23 '17 at 17:30
  • @Jaap: I don't have any reproducible data. As this has been saved by someone else. I'm trying to load it and save it as a dataframe, that is all. – joeblow May 23 '17 at 17:46

2 Answers2

0

An RDA file is, by definition, a file that has been persisted to disk and is not to be confused with a variable that is in memory (or your workspace). To read in .RDA files you use load(file = "<path>"). If you have the path of your .RDA file you can use this:

load(file = "<your path>/<your filename>.RDA")
write.csv(<var name>, file="out.csv") 

Make sense?

Zafar
  • 1,897
  • 15
  • 33
  • Yeah - this makes sense. And I thought this would be this simple... but it gives me the error: unused argument (path="/.RDA") – joeblow May 23 '17 at 17:30
  • oh, right sorry that was from the `.rds` function. I'm updating. – Zafar May 23 '17 at 22:18
  • `load(file = "/data/myfile.rda")` remember this always picks up the file from the current working directory. If you need to know what that is use `getwd()` and set it using `setwd()`. – Zafar May 23 '17 at 22:20
0

Seeing that you have an object of class character, i.e. a vector of strings, you can use cat to write it to a file.

df <- LETTERS # = c("A", "B", ..., "Z")
cat(df, file = "my/path/to/data.txt", sep = "\n", append = FALSE)

Now the file will have the contents

A
B
C
...
Z
AlexR
  • 2,412
  • 16
  • 26