2

I'm using RStudio Server version 0.99.903 and I want to create a script to export a data frame to my local machine running Windows 7. I can successfully export the data frame manually to the hard drive following the steps described HERE.

I have searched SO extensively. So far nothing has worked.

Any help would be greatly appreciated.

Community
  • 1
  • 1
  • this would be very convenient. I don't think rStudio server can do this (I can't find a way either). It's relying on the browser to do the work of actually interacting with your OS. – justin cress Nov 30 '17 at 23:21

1 Answers1

1

Guessing since no access to Windows 7, based on this

write_to_desktop <- function(df,fn="tmp.csv",...) {
   dskpath <- file.path("C:",Sys.getenv("USER"),"Desktop",fn)
   write.csv(df,file=dskpath,...)
}

You could modify this to try to guess the file name from the name of the data frame (fn <- paste0(deparse(substitute(df)),".csv")) or to write a .rda file (save()) or a .rds file (saveRDS()) ...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Thank you for your answer. It's very straightforward. However, I got an error when I ran the function: `write_to_desktop (dfdata, "mydata.rda")` `Error in file(file, ifelse(append, "a", "w")) :` `cannot open the connection` – user3807006 Nov 04 '16 at 21:07
  • I should add when I check if mydata.rda exists and I know it exists the output is FALSE. `file.exists(file.path("C:", "Users", Sys.getenv("USER"),"Desktop","mydata.rda"))` `[1] FALSE` – user3807006 Nov 04 '16 at 21:15
  • how about `file.path(normalizePath("~/Desktop"),"mydata.rda")` ? – Ben Bolker Nov 05 '16 at 02:55
  • This doesn't seem to work either and this may be due to the fact I'm using RStudio Server in the cloud i.e. within a browser (firefox 40.03). I may need to trigger a download event from the browser and that I don't know how to do it. Thanks again for your help. – user3807006 Nov 07 '16 at 17:36