r - How to use imported functions in examples -


i have package imports functions package. can use functions without qualifier in regular code, not in examples, seems. demonstrate:

here's low-level package export function a.

library(devtools) library(roxygen2)  create("lowlevel") cat(   "#' function in lowlevel pacakge. #'  #' nothing interesting. #' @return 1 #' @export <- function() 1 ",   file = "lowlevel/r/a.r" ) 

here's high-level package wants use a in example.

create("highlevel") cat(   "#' function in highlevel package. #'  #' nothing interesting. #' @return 2 #' @examples #' a() + b() #' @importfrom lowlevel #' @export b <- function() 2 ",   file = "highlevel/r/b.r" ) 

now build , install packages:

roxygenize("lowlevel") roxygenize("highlevel") install.packages(build("lowlevel"), repos = null, type = "source") install.packages(build("highlevel"), repos = null, type = "source") 

when run example, error.

library(highlevel) example(b) ## error in eval(expr, envir, enclos) : not find function "a" 

highlevel know function, since namespace file contains line:

importfrom(lowlevel,a) 

i can make example work give qualified name, lowlevel::a makes clunky read.

is there way use imported functions in examples without qualifying names?

the point of importing function make available other functions in package, that's why don't have problem using a in package code.

if want use function in examples, have make function available user in global environment, i.e. either need export or use library(lowlevel).


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -