[R] Package renv and Rscript

Ben Tupper btupper @end|ng |rom b|ge|ow@org
Tue Apr 14 19:52:37 CEST 2020


Whoops!  The silly "send" button jumped out and grabbed my cursor before I
was ready for it.  Second try...

I am using renv (https://rstudio.github.io/renv/) to maintain a project
environment in a directory (ala '/path/to/project').

Within the project I have a number of scripts that I call with one argument
using...

$ Rscript /path/to/script.R /path/to/config_file

I can kick this off successfully with the renv environment when I manually
start Rscript within the project directory. Now I would like to be able to
hand the script kick-off to either crontab or the PBS queueing system.  But
I haven't figured out how to get the instance of R that is kicked off to do
so using the renv project space (i.e. using the R libraries as established
in the project.)

At first I thought I would call a simple wrapper script such that accepted
two arguments '/path/to/script.R' and '/path/to/config_file'. I planned to
use ...

###
args <- commandArgs(trailingOnly = TRUE)
path_to_script <- args[1]
path_to_config <- args[2]
renv::run(path_to_script,
          project = '/path/to/project')
###

Unfortunately renv::run() doesn't provide a vehicle for passing other
script arguments along.  So, in this case, there's no way to communicate
the configuration file to the script.

Is there a recommended way to call Rscript such that the renv environment
gets picked up?

Thanks!
Ben


On Tue, Apr 14, 2020 at 1:41 PM Ben Tupper <btupper using bigelow.org> wrote:

> Hi,
>
> I am using renv (https://rstudio.github.io/renv/) to maintain a project
> environment in a directory (ala /path/to/project)
>
>
> Within the project I have a number of scripts that I call using...
>
> $ Rscript /path/to/script.R /path/to/config_file
>
> I can kick this off successfully with the renv environment when I manually
> start Rscript within the project directory. Now I would like to be able to
> hand the script kick off to either crontab or the PBS queueing system.
>
> At first I thought I would actually call a wrapper script such that
> accepted two arguments '/path/to/script.R' and '/path/to/config_file'. I
> planned to use
>
> renv::run('/path/to/script.R',
>
>
> --
> Ben Tupper
> Bigelow Laboratory for Ocean Science
> East Boothbay, Maine
> http://www.bigelow.org/
> https://eco.bigelow.org
>
>

-- 
Ben Tupper
Bigelow Laboratory for Ocean Science
East Boothbay, Maine
http://www.bigelow.org/
https://eco.bigelow.org

	[[alternative HTML version deleted]]



More information about the R-help mailing list