## ---------------------------------------------------------------------
## Testing package functions
## ---------------------------------------------------------------------
## Not run:
# library(myPkg)
#
# ## Test exported functions by name or the double colon:
# bpvalidate(myExportedFun)
# bpvalidate(myPkg::myExportedFun)
#
# ## Non-exported functions are called with the triple colon:
# bpvalidate(myPkg:::myInternalFun)
# ## End(Not run)
## ---------------------------------------------------------------------
## Testing workspace functions
## ---------------------------------------------------------------------
## Functions defined in the workspace have the .GlobalEnv as their
## environment. Often the symbols used inside the function body
## are not defined in .GlobalEnv and must be passed explicitly.
## Loading libraries:
## In 'fun1' countBam() is flagged as unknown:
fun1 <- function(fl, ...)
countBam(fl)
bpvalidate(fun1)
## countBam() is not defined in .GlobalEnv and must be passed as
## an argument or made available by loading the library.
fun2 <- function(fl, ...) {
library(Rsamtools)
countBam(fl)
}
bpvalidate(fun2)
## Passing arguments:
## 'param' is defined in the workspace but not passed to 'fun3'.
## bpvalidate() flags 'param' as being found 'inPath' which means
## it is not defined in the function environment or inside the function.
library(Rsamtools)
param <- ScanBamParam(flag=scanBamFlag(isMinusStrand=FALSE))
fun3 <- function(fl, ...) {
library(Rsamtools)
countBam(fl, param=param)
}
bpvalidate(fun3)
## 'param' is explicitly passed by adding it as a formal argument.
fun4 <- function(fl, ..., param) {
library(Rsamtools)
countBam(fl, param=param)
}
bpvalidate(fun4)
## The corresponding call to a bp* function includes 'param':
## Not run: bplapply(files, fun4, param=param, BPPARAM=SnowParam(2))
Run the code above in your browser using DataLab