When a process runs, your base directory is the working directory and R files are not within the same folder. Instead, the R files have been added to the PATH
variable, which means you can call them but they are not directly accessible using source or any other local file operations.
One potential solution is to add the bin/
path as a variable.
βIf we have an R file in bin/
called source.R
:
hello_world <- function() {
print("Hello World!")
}
To source this file we can read the PATH
variable, take the last value (which is the bin/
added by Nextflow), and import the source.R
file from this path explicitly.
process IMPORT_R {
container 'docker.io/library/r-base:4.3.1'
output:
stdout
script:
"""
#!/usr/bin/Rscript --vanilla
path <- Sys.getenv("PATH") |> strsplit(":")
bin_path <- tail(path[[1]], n=1)
source(file.path(bin_path, "source.R"))
hello_world()
"""
}
Another solution could be to combine your R scripts into one file or use the R file as an input to the process.