knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Before you start see the
Getting started with BiocProject vignette for
the basic information and installation instructions.
Get paths to the files used in this vignette
library(BiocProject) ProjectConfigArgs = system.file( "extdata", "example_peps-master", "example_BiocProject", "project_config_resize.yaml", package = "BiocProject" ) readBedFiles_resize = system.file( "extdata", "example_peps-master", "example_BiocProject", "readBedFiles_resize.R", package = "BiocProject" )
What if your custom data processing function requires more arguments than just a PEP?
For reference consider the readBedFiles_resize.R function and its interface.
This function additionally requires the resize.width argument.
processFunction = system.file( "extdata", "example_peps-master", "example_BiocProject", "readBedFiles_resize.R", package="BiocProject" ) source(processFunction)
readBedFiles_resize
There are a few ways to enable your function to get multiple
arguments - not just a PEP
(pepr::Project)
object, which is the basic scenario.
The options:
funcArgs argument of BiocProject functionfunc argument of BiocProject functionThe easiest way to provide addtional arguments to your data reading/processing function is to add addtional section in the config file. See the config file below for reference:
library(pepr) config_resize = configFile = system.file( "extdata", "example_peps-master", "example_BiocProject", "project_config_resize.yaml", package = "BiocProject" ) .printNestedList(yaml::read_yaml(config_resize))
The section funcArgs was added within the bioconductor section.
bp = BiocProject(ProjectConfigArgs) bp
funcArgs argumentProvide additional funcArgs argument to the BiocProject function.
This argument has to be a named list. The names have to correspond to the
argument names of your function.
The PEP will be passed to your function by default. For example:
Read the function into R environment and run the BiocProject function with
the funcArgs argument
library(BiocProject) ProjectConfigArgs = system.file( "extdata", "example_peps-master", "example_BiocProject", "project_config_resize.yaml", package = "BiocProject" ) readBedFiles_resize = system.file( "extdata", "example_peps-master", "example_BiocProject", "readBedFiles_resize.R", package = "BiocProject" )
source(readBedFiles_resize) bpArgs = BiocProject(file=ProjectConfigArgs, funcArgs=list(resize.width=200)) bpArgs
The funcArgs argument gets a one element list and passes the resize.width
argument to your custom data processing function. If any arguments are present
in the config file, they will be overwritten (the width of the ranges has
changed from 100 to 200 in the example above).
You can use an
anonymous function
(that is implemented in the BiocProject function call) to provide additional
arguments to your function of interest. For example:
bpAnonymous = BiocProject(file=ProjectConfigArgs, func=function(x){ readBedFiles_resize(project=x, resize.width=100) } ) #Inspect it bpAnonymous
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.