The workspace can be saved to file when closing an R or RStudio session. It contains all of the objects in your namespace when the previous session was close if save workspace is set as the default element or chosen as the option on exit manually.
You do not need the workspace to run an R script unless the script depends on objects created outside the script and not saved to file. For example
To debug, try navigating to the location with your R script and
source("my_script.R")
which will perform whatever operations it performs and complain about missing objects it expects or, if so specified, read data from file and transform it into the objects it needs.
Thanks for your reply
I tried what you suggested, and that is what I got
setwd("D:/my_folder")
source("my_script.R")
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'my_script.R': No such file or directory
so Sonia
lets not be secretive, you can tell your actual script name to us, and probably nothing bad would happen
in practical advice, I would verify you have what you think you have locationwise by using the dir() function to look at your present working directories contents and seeing that your script is sat there, spelt exactly as it would be when you try to source it in...
This relates to namespace, the objects that Rknows about. These are the {base} libraries, libraries loaded into the session, and objects restored from an Rds file or read in by read.csv, for exaple.
> setwd("D:/my_folder")
> source("my_script.R")
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'my_script.R': No such file or directory
> setwd("D:/my_folder")
Warning message:
file β.RDataβ has magic number ''
Use of save versions prior to 2 is deprecated
> dir()
[1] "my_script.R"
> source("my_script.R")
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'my_script.R': No such file or directory
I'm scratching my head very hard.
What happens when you load my_script into the RStudio Editor by the File menu, Open (or Control+O) shortcut ?
Does the script show with any issues ?
Will the script run without errors under that circumstance ?