I am using R studio.
Is there a way to find out if the R script is executed directly either by the source command in the console), or inside another script. i.e. another script is received, and this is a call to the first script.
This may be useful for querying some values โโin some cases.
What I am doing now is setting the variable to true or false, and in the script I check this variable. It works, but the automatic way is better.
Thank you for your time.
EDIT: More info
Suppose I have an independent script that works just as it is, but this script is part of the process that runs after the completion of another script. If I need to run both, I can run the first, then the second; but also I have a chance to just launch a second one.
I ask if there is a way (in the second scenario) to check if this second was called from the first or not.
Take a look at his simple examples (inspired by Greg Snow 's answer). First the file that I call in Rstudio
# scripta.R writeLines("script A") if (interactive()) writeLines("interactive: true") else writeLines("interactive false") source("scriptb.r") writelines("after B")
Then file received
# scriptb.R writeLines("script B") if (interactive()) writeLines("interactive: true") else writeLines("interactive false") writeLines("end B")
Result in Rstudio
script A interactive: true script B interactive: true end B after B
I like to have something like
script A interactive: true script B interactive: false end B after B
I hope itโs now clearer.
thanks
notuo
source share