0

I have a particular R script which I regularly in RStudio to scrape data from the internet. I would like to set up a batch file to run this file automatically and therefore want to run this script directly from R. However, the data frames and objects recognized in RStudio are not recognized in R. I'm no expert in R but have searched this topic but forgive my if I've missed the solution posted elsewhere.

Specifically, when working in RStudio I used getwd() which returns "C:/Users/mdoucette001/Desktop/Beer Stuff/R Beer Stuff/". I have run save.image() to ensure that the output (data frames, lists, etc) created in RStudio is being saved. When I try to run this in R, the first line of code I run is setwd("C:/Users/mdoucette001/Desktop/Beer Stuff/R Beer Stuff"). If I compare data frames in R and RStudio (e.g. nrow(df1) ) I get a different response between the two. Because the R rowcount is smaller, I suspect that it is somehow loading an old image/workspace. What am I missing?

user1267653
  • 11
  • 1
  • 2

2 Answers2

0

Pass the working directory to batch-mode R as a command argument, as described in this question:

Passing command line arguments to R CMD BATCH

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
0

You've used save.image() but have you loaded the image back into the session? You need to do that explicitly.

Jonathan Carroll
  • 3,897
  • 14
  • 34