0

I am using a Linux Workstation to run my R script. I did so using screen and then Rscript myRscript.R. Is there anyway to access the R session after the script has run? I want to be able to write new commands and access the global environment that was created during that session.

I tried asking the Unix community, but no response... https://unix.stackexchange.com/questions/608073/how-to-pass-code-to-attached-screen

1 Answer 1

2

The session is lost after the script is done running. But you can save the environment using save.image("env_file.Rdata") and use it later using load("env_file.Rdata").

See http://ugrad.stat.ubc.ca/R/library/base/html/save.html

Sign up to request clarification or add additional context in comments.

2 Comments

My script did not make it to the end, something went wrong along the way. Do you know if Rscript --save myRscript.R would save the workspace where ever it stops even if it does not make it to the end of the script?
I don't think it would save the workspace if there's an error. If you want to debug the script, maybe can use the R console instread ofsource("myscript.R") and then use save.image. Or maybe using Rscript -e "tryCatch({source('myRscript.R')}); save.image('env_file.Rdata')" to use tryCatch to handle any error and save the environement image anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.