Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading datasets during `run_examples()` #242

Closed
wibeasley opened this Issue Jan 30, 2013 · 5 comments

Comments

Projects
None yet
3 participants
@wibeasley
Copy link
Contributor

wibeasley commented Jan 30, 2013

@hadley requested that I file this as a devtools bug:

I think this issue reflects a problem with my understanding of devtools, but it's possible it's my understanding with r2oxygen.

When I run devtools::run_examples(), it throws an error when the example includes a data.frame that I haven't loaded explicitly with data(). I've set LazyData to TRUE in the DESCRIPTION file

Unexpectedly to me, the error isn't thrown when I run devtools::check() or click RStudio's check button. When I reverted back to devtools 0.8, the same behavior existed, so it's not an issue with devtools 1.0.

There are two ways I can avoid the problem with devtools::run_examples():

  1. load the data.frame with data() See this on GitHub, or

  2. Append exportPattern("^[[:alpha:]]+") to the NAMESPACE file created by devtools::document(roclets = c("collate", "namespace","rd") ) before executing devtools::run_examples().

I'd like to learn what specific object(s) need to be added to the existing NAMESPACE file, and what I need to do improve my roxygen2 comments.

Also, I'm curious why devtools::run_examples() returns an error, but devtools::check() does not?

Please tell me if there any other information that I can provide to describe or recreate the scenario better. Thanks, Will

@wibeasley

This comment has been minimized.

Copy link
Contributor Author

wibeasley commented Jan 30, 2013

If this helps diagnose anything, the package (version 1.201) was built successfully by R-Forge for all three OSes: https://r-forge.r-project.org/R/?group_id=1330

The widely permission exportPattern (see (2) in my initial post) was NOT included in that namespace file (see here).

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Mar 28, 2013

@wch I think this is a namespace bug - when export_all is false, datasets should still be available, even though they're not explicitly exported in the NAMESPACE

@wch

This comment has been minimized.

Copy link
Member

wch commented Apr 1, 2013

It looks like load_data and load_all currently don't handle data objects quite right. When a package is loaded the normal way, the data is in the package environment, but not the namespace:

library(plyr)
ns <- asNamespace('plyr')
head(ns$baseball)
# NULL

pkg <- as.environment('package:plyr')
head(pkg$baseball)
# [prints out data]

But when you use load_all, it gets loaded into the namespace first, then is copied to the package environment (if export_all==TRUE):

load_all()
ns <- asNamespace('plyr')
head(ns$baseball)
# [prints out data]

pkg <- as.environment('package:plyr')
head(pkg$baseball)
# [prints out data]

Maybe it should use the lazy-loading code from R? https://github.com/wch/r-source/blob/trunk/src/library/base/R/namespace.R#L426

Edit: Nevermind about the lazy-loading; that requires .rdb and .rdx files, which (I think) are generated when the package is built.

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Apr 1, 2013

Maybe it's a bug in load_data - currently the dataset in data/ are getting loaded into the namespace environment - but maybe they should be loaded into the package env?

@wch

This comment has been minimized.

Copy link
Member

wch commented Apr 1, 2013

I think when lazyLoad is called, it puts a "promise" into nsenv$.__NAMESPACE__.$lazydata, and those somehow get copied into the package environment. For example, this will print out the data:

library(plyr)
ns <- asNamespace('plyr')
head(ns$.__NAMESPACE__.$lazydata$baseball)

I tried sImply copying objects into $lazydata, and that's apparently not quite enough -- they don't show up in the package env. So I'm going to also have the export process copy objects from $lazydata to the package env.

@hadley hadley closed this in c764886 Apr 1, 2013

hadley added a commit that referenced this issue Apr 2, 2013

@lock lock bot locked and limited conversation to collaborators Sep 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.