knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

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"
)

Ways to provide addtional arguments

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:

How to provide addtional section in the config file

The 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

How to use the funcArgs argument

Provide 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).

How to use an anonymous function

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


pepkit/BiocProject documentation built on July 28, 2023, 2:49 p.m.