new_rscript {slurmR} | R Documentation |
General purpose function to write R scripts
Description
This function will create an object of class slurmR_rscript
that can be used
to write the R component in a batch job.
Usage
new_rscript(
njobs,
tmp_path,
job_name,
pkgs = list_loaded_pkgs(),
libPaths = .libPaths()
)
Arguments
njobs |
Integer. Number of jobs to use in the job-array. This specifies the number of R sessions to initialize. This does not specify the number of cores to be used. |
tmp_path |
Character. Path to the directory where all the data (including scripts) will be stored. Notice that this path must be accessible by all the nodes in the network (See opts_slurmR). |
job_name |
Character. Name of the job to be passed to |
pkgs |
A named list with packages to be included. Each element of the list must be a path to the R library, while the names of the list are the names of the R packages to be loaded. |
libPaths |
A character vector. See .libPaths. |
Value
An environment of class slurmR_rscript
. This has the following accessible
components:
-
add_rds
Add rds files to be loaded in each job.",x
is a named list with the objects that should be loaded in the jobs. Ifindex = TRUE
the function assumes that the user will be accessing a particular subset ofx
during the job, which is accessed according toINDICES[[ARRAY_ID]]
. The optioncompress
is passed to saveRDS.One important side effect is that when this function is called, the object will be saved in the current job directory, this is
opts_slurmR$get_tmp_path()
. -
append
Adds a line to the R script. Its only argument,x
is a character vector that will be added to the R script. -
rscript
A character vector. This is the actual R script that will be written at the end. -
finalize
Adds the final line of the R script. This function receives a character scalarx
which is used as the name of the object to be saved. If missing, the function will save a NULL object. Thecompress
argument is passed to saveRDS. -
set_seed
Adds a vector of seeds to be used across the jobs. This vector of seeds should be of lengthnjobs
. The other two parameters of the function are passed to set.seed. By default the seed is picked as follows:seeds <- sample.int(.Machine$integer.max, njobs, replace = FALSE)
-
write
Finalizes the process by writing the R script in the corresponding folder to be used with Slurm.