[Bioc-devel] installed, system.file(package="RCyjs") is "/Users/biocbuild/bbs-3.8-bioc/meat/RCyjs.buildbin-libdir/RCyjs"

Martin Morgan m@rtin@morg@n @ending from ro@wellp@rk@org
Sat Jun 30 01:11:40 CEST 2018



On 06/29/2018 06:44 PM, Paul Shannon wrote:
> My package RCyjs reads an html/js/css file when the constructor is called, then sends that file to the user’s browser.
> 
> The actual path to that file is calculated at global scope in RCyjs-class.R:
> 
>     cyjsBrowserFile <- system.file(package="RCyjs", "browserCode", "dist", "rcyjs.html”)
> 
> That file cannot be found at runtime.  Using
> 
>    options(error=recover)
> 
> I can trap that error, finding these two different interpretations of system.file(package=“RCyjs”):
> 
>     cyjsBrowserFile:
>         "/Users/biocbuild/bbs-3.8-bioc/meat/RCyjs.buildbin-libdir/RCyjs/browserCode/dist/rcyjs.html”
>      system.file(package="RCyjs")
>        "/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RCyjs”
> 
> It appears that cyjsBrowserFile is assigned at the build system’s package construction time, not at the package load and use time.
> 
> Maybe this is new behavior?   Any suggestions on how to defer the calculation of system.file(package=“RCyjs”) till run time?
> 

you have the assignment at the 'top' level of your package R code

cyjsBrowserFile <- system.file(package="RCyjs", ...)

so that it gets evaluated when R source()s the file (approximately) to 
create the package. The correct paradigm would be to create the 
reference when the package is loaded, using .onLoad

cyjsBrowserFile <- NULL     # create symbol when built

.onLoad <- function(...) {
     cyjsBrowserFile <<- system.file(...  # assign symbol (using <<-) on 
load
}

Martin

> Thanks!
> 
>   - Paul
> 
> _______________________________________________
> Bioc-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
> 


This email message may contain legally privileged and/or...{{dropped:2}}



More information about the Bioc-devel mailing list