Cannot Export Data to a File in R (Write.Csv)

Cannot export data to a file in R (write.csv)

First part is to check the working directory and ensure that you have write access to that directory. You can check this with getwd(). I can reproduce your error by trying to write to a directory which is read only.

To set the working directory to something else with read access you can type setwd("H:/foo").
Once you have write access the write.csv(x,file='whatever.csv') should work.

Using write.csv() function in R but it doesn't actually save it to my C:

In my opinion, the simplest way would be to save the file to the same folder that rstudio is running in, and use the rstudio gui. It should be write.csv(daily_steps, "./daily_steps.csv") (no quotes around the function), and then on the tab in the bottom right of rstudio, you can select files, and it should be there. Then you can use the graphic user interface to move it to your desktop in a way analogous to what you would do in MS word.

Exporting Data to CSV in R

You did not assign the results of do.call function to anything. Fairly common R noob error. Failure to understand the functional programming paradigm. Results need to be assigned to R names or they just get garbage-collected.

The error is actually from the code that you didn't put in a code block:

write.csv(read.csv, file ='Lineups.csv')

The 'read.csv' was presumably your intended name for the result of the do.call-operation, except it is by default a function name rather than your expectation. You could assign the do.call-results to the name 'read.csv' but doing so is very poor practice. Choose a more descriptive name like 'TEMP_files_appended'.

TEMP_files_appended <- do.call("rbind",lapply(filenames, read.csv, header = TRUE))

write.csv(TEMP_files_appended, file ='Lineups.csv')

(I will observe that using header=TRUE for read.csv is not needed since that is the default for that function.)



Related Topics



Leave a reply



Submit