[R-pkg-devel] referring to a package data object by two names

Gregory Jefferis jefferis at gmail.com
Mon Oct 9 20:39:07 CEST 2017


Thanks, Berry. Interesting! Both this suggestion and my previous effort seem a little baroque – fighting against the system.

However after thinking about this some more, I found this:

delayedAssign('landmarks', testdataalias::landmarks.2017)

which feels a bit safer (although does not try to automatically find the most recent object as per your suggestion).

Thanks again,

Greg.


> On 9 Oct 2017, at 13:36, Berry Boessenkool <berryboessenkool at hotmail.com> wrote:
> 
> 
> Another approach, maybe overkill / not thought through:
> 
> latestLandmark <- function()
>  {
>  files <- dir(file.path(system.file(package="yourpackage"), "data"), 
>               pattern="landmark", full.names=TRUE)
>  env <- environment()
>  dataset <- load(tail(files, 1), envir=env)
>  return(invisible(get(dataset, envir=env)))
>  }
> 
> landmark <- latestLandmark()
> 
> 
> Regards,
> Berry
> 
> 
> From: R-package-devel <r-package-devel-bounces at r-project.org <mailto:r-package-devel-bounces at r-project.org>> on behalf of Gregory Jefferis <jefferis at gmail.com <mailto:jefferis at gmail.com>>
> Sent: Sunday, October 8, 2017 14:45
> To: Michael Dewey
> Cc: r-package-devel at r-project.org <mailto:r-package-devel at r-project.org>
> Subject: Re: [R-pkg-devel] referring to a package data object by two names
>  
> Dear Michael,
> 
> Many thanks for writing.
> 
> > Do any of the suggestions in section 1.5.3 of Writing R Extensions "Load hooks" work?
> 
> I thought I had tried all the various permutations in .onLoad but at your prompting I tried some more and this seems to work:
> 
> .onLoad <- function (libname, pkgname) {
>   # set up default landmarks object
>   assign('landmarks',
>          envir = parent.env(environment()),
>          testdataalias::landmarks.2017)
> 
> }
> 
> It doesn't seem to tickle R CMD check, but I'm not yet convinced that it is 100% safe. Any comments either way are welcome!
> 
> Best wishes,
> 
> Greg.
> 
> ______________________________________________
> R-package-devel at r-project.org <mailto:R-package-devel at r-project.org> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel <https://stat.ethz.ch/mailman/listinfo/r-package-devel>
--
Gregory Jefferis, PhD
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://www.zoo.cam.ac.uk/departments/connectomics




	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list