cgat-developers/cgat-core

How can I convert a parameter from the YAML file into an R vector

Closed this issue · 3 comments

Hi,

I have a parameter in my R script, exp_names, which is a vector (c("BL1", "BL2")). How can I pass an R vector from the pipeline.yml file into the rmarkdown::render call?

@merge(PARAMS["input_files"],
       PARAMS["working_dir"] + 
       "/results/Robjects/merged/seurat_merged.rds")
def merge_seurat(infiles, outfile):
    '''Merge Seurat objects from multiple experiments'''

    statement = '''cd %(wd)s &&
                module load R-cbrg &&
                Rscript -e
                "rmarkdown::render(
                    input = 'Rscripts/4-merge_seurat.Rmd',
                    output_format = 'html_document',
                    output_file = 'merge_seurat.html',
                    output_dir = 'reports',
                    params = list(working_dir = '%(wd)s',
                                  exp_names = %(merge_exp_names)s))"'''

    P.run(statement)

Thanks,
Lucy

Did you manage to work this one out?

For me, I would probably use rpy2.

For example: from rpy2.robjects.packages import importr
exp_names = robjects.StrVector(["BL1", "BL2"])

r_base = importr('base')
r_rmarkdown = importr('rmarkdown')
input_file = "path/to/your/input.Rmd"
output_file = "path/to/your/output.html"

r_rmarkdown.render(
input_file,
output_format="html_document",
output_file=output_file,
params=robjects.ListVector({"exp_names": exp_names}),
)

Feel free to reopen, sorry but been really busy for months and only getting around to checking issues for repos now