Coder Social home page Coder Social logo

pkgload's Introduction

pkgload

Codecov test coverage R-CMD-check

The goal of pkgload is to simulate the process of installing and loading a package, without actually doing the complete process, and hence making package iteration much faster. This was previously part of devtools (it was in fact the original motivation) but has been moved into its own package as part of the devtools conscious uncoupling.

Usage

In most cases you will not use pkgload directly, and instead you'll call it via devtools::load_all().

devtools::load_all()

Code of Conduct

Please note that the pkgload project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

pkgload's People

Contributors

adrtod avatar bpbond avatar craigcitro avatar dfalbel avatar ethanplunkett avatar gaborcsardi avatar geoff99 avatar hadley avatar henrikbengtsson avatar jennybc avatar jiho avatar jimhester avatar jjallaire avatar karl-forner-quartz-bio avatar kevinushey avatar klmr avatar kohske avatar krlmlr avatar lionel- avatar michaelchirico avatar musvaage avatar ncarchedi avatar neshvig10 avatar olivroy avatar pitakakariki avatar rmflight avatar robertzk avatar wch avatar yiufung avatar yoni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pkgload's Issues

load_all fails with package including a DLL

Issue by stla
Tuesday Jun 20, 2017 at 16:24 GMT
Originally opened as r-lib/devtools#1529


Hello,

I have a package with a DLL in inst/libs. It works very well. I did some testthat tests which work when I run them in the console. But devtools::test() generates an error because of load_all:

> devtools:::load_all(".")
Loading hwriteXLSX
Error in library.dynam("json2xlsx", pkgname, libname) : 
  DLL ‘json2xlsx’ not found: maybe not installed for this architecture?
Called from: library.dynam("json2xlsx", pkgname, libname)

Should `helper.R` assume the testthat namespace is attached?

I have a helper.R file that defines custom skippers and, depending on the situation, might call one of them in helper.R, in order to emit a message for the benefit of travis and appveyor logs.

This taught me that skip() can't be found when helper.R is run via check() (whereas it is found when the helpers are run via test()).

Should we write helper.R to assume that the testthat namespace is attached or not?

pkgload/R/load.r

Lines 193 to 198 in 80a6493

# Source test helpers into package environment
if (uses_testthat(path) && helpers) {
withr::with_envvar(c(NOT_CRAN = "true", DEVTOOLS_LOAD = "true"),
testthat::source_test_helpers(find_test_dir(path), env = ns_env(package))
)
}

print.dev_topic() fails to render

> load_all("../rmini")
Loading rmini
Re-compiling rmini
'/usr/lib64/R/bin/R' CMD INSTALL '/home/nacnudus/R/rmini' --library='/tmp/Rtmp4nfXAc/devtools_install_472b41ef1bca' --no-R --no-data --no-help --no-demo --no-inst --no-docs --no-exec --no-multiarch --no-test-load
make: Nothing to be done for 'all'.
> dev_help("hello")
Rendering development documentation for 'hello'
Error in if (nzchar(package)) { : argument is of length zero
>

Use rstudioapi to save open files

In load_all()

Alternatively, we could call load_all() something more descriptive here, and then in devtools load_all() would become a wrapper in the same way that test(), document() etc are.

Failing to compile

This is inside a Docker container running Debian 9 (R 3.3.1). It worked yesterday.

2018-02-15_16:28:00.88631 Installing pkgdown
2018-02-15_16:28:06.56412 Downloading GitHub repo r-lib/pkgload@master
2018-02-15_16:28:06.56414 from URL https://api.github.com/repos/r-lib/pkgload/zipball/master
2018-02-15_16:28:06.72946 Installing pkgload
2018-02-15_16:28:08.70497 '/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet  \
2018-02-15_16:28:08.70499   CMD INSTALL '/tmp/RtmpSF0P82/devtools1ef4f32637e/r-lib-pkgload-f2cc46f'  \
2018-02-15_16:28:08.70499   --library='/usr/local/lib/R/site-library' --install-tests 
2018-02-15_16:28:08.70509 
2018-02-15_16:28:08.95391 * installing *source* package 'pkgload' ...
2018-02-15_16:28:08.98392 ** libs
2018-02-15_16:28:08.99211 gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-3.3.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c unlock.c -o unlock.o
2018-02-15_16:28:09.02434 unlock.c:5:14: error: unknown type name 'R_CallMethodDef'
2018-02-15_16:28:09.02436  static const R_CallMethodDef CallEntries[] = {
2018-02-15_16:28:09.02436               ^~~~~~~~~~~~~~~
2018-02-15_16:28:09.02436 unlock.c:6:5: warning: braces around scalar initializer
2018-02-15_16:28:09.02436      {"unlock_environment_", (DL_FUNC) &unlock_environment_, 1},
2018-02-15_16:28:09.02437      ^
2018-02-15_16:28:09.02437 unlock.c:6:5: note: (near initialization for 'CallEntries[0]')
2018-02-15_16:28:09.02437 unlock.c:6:6: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
2018-02-15_16:28:09.02438      {"unlock_environment_", (DL_FUNC) &unlock_environment_, 1},
2018-02-15_16:28:09.02438       ^~~~~~~~~~~~~~~~~~~~~
2018-02-15_16:28:09.02438 unlock.c:6:6: note: (near initialization for 'CallEntries[0]')
2018-02-15_16:28:09.02438 unlock.c:6:6: error: initializer element is not computable at load time
2018-02-15_16:28:09.02439 unlock.c:6:6: note: (near initialization for 'CallEntries[0]')
2018-02-15_16:28:09.02439 unlock.c:6:30: error: 'DL_FUNC' undeclared here (not in a function)
2018-02-15_16:28:09.02440      {"unlock_environment_", (DL_FUNC) &unlock_environment_, 1},
2018-02-15_16:28:09.02440                               ^~~~~~~
2018-02-15_16:28:09.02441 unlock.c:6:29: warning: excess elements in scalar initializer
2018-02-15_16:28:09.02441      {"unlock_environment_", (DL_FUNC) &unlock_environment_, 1},
2018-02-15_16:28:09.02441                              ^
2018-02-15_16:28:09.02442 unlock.c:6:29: note: (near initialization for 'CallEntries[0]')
2018-02-15_16:28:09.02442 unlock.c:6:61: warning: excess elements in scalar initializer
2018-02-15_16:28:09.02442      {"unlock_environment_", (DL_FUNC) &unlock_environment_, 1},
2018-02-15_16:28:09.02442                                                              ^
2018-02-15_16:28:09.02442 unlock.c:6:61: note: (near initialization for 'CallEntries[0]')
2018-02-15_16:28:09.02442 unlock.c:7:5: warning: braces around scalar initializer
2018-02-15_16:28:09.02443      {NULL, NULL, 0}
2018-02-15_16:28:09.02443      ^
2018-02-15_16:28:09.02443 unlock.c:7:5: note: (near initialization for 'CallEntries[1]')
2018-02-15_16:28:09.02445 unlock.c:7:6: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
2018-02-15_16:28:09.02445      {NULL, NULL, 0}
2018-02-15_16:28:09.02445       ^~~~
2018-02-15_16:28:09.02445 unlock.c:7:6: note: (near initialization for 'CallEntries[1]')
2018-02-15_16:28:09.02446 unlock.c:7:12: warning: excess elements in scalar initializer
2018-02-15_16:28:09.02446      {NULL, NULL, 0}
2018-02-15_16:28:09.02446             ^~~~
2018-02-15_16:28:09.02446 unlock.c:7:12: note: (near initialization for 'CallEntries[1]')
2018-02-15_16:28:09.02447 unlock.c:7:18: warning: excess elements in scalar initializer
2018-02-15_16:28:09.02447      {NULL, NULL, 0}
2018-02-15_16:28:09.02447                   ^
2018-02-15_16:28:09.02447 unlock.c:7:18: note: (near initialization for 'CallEntries[1]')
2018-02-15_16:28:09.02449 unlock.c:10:21: error: unknown type name 'DllInfo'
2018-02-15_16:28:09.02450  void R_init_pkgload(DllInfo *dll) {
2018-02-15_16:28:09.02450                      ^~~~~~~
2018-02-15_16:28:09.02715 /usr/lib/R/etc/Makeconf:132: recipe for target 'unlock.o' failed
2018-02-15_16:28:09.02715 make: *** [unlock.o] Error 1

Can't install pkgload

You may know this, but pkgload can't be installed from github. This blocks me from installing pkgdown

> devtools::install_github("r-lib/pkgload")
Downloading GitHub repo r-lib/pkgload@master
from URL https://api.github.com/repos/r-lib/pkgload/zipball/master
Installing pkgload
"C:/R/R-3.4.1/bin/x64/R" --no-site-file --no-environ --no-save --no-restore  \
  --quiet CMD INSTALL  \
  "C:/Users/friendly/AppData/Local/Temp/Rtmp23AVmF/devtools145864e75f23/r-lib-pkgload-7fd5f55"  \
  --library="C:/R/R-3.4.1/library" --install-tests 

* installing *source* package 'pkgload' ...
** R
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for 'pkgload':
 .onLoad failed in loadNamespace() for 'pkgload', details:
  call: is_null(x)
  error: object 'rlang_is_null' not found
Error: loading failed
Execution halted
ERROR: loading failed
* removing 'C:/R/R-3.4.1/library/pkgload'
Installation failed: Command failed (1)
> 

Multiple remotes in DESCRIPTION

Issue by muschellij2
Tuesday Sep 13, 2016 at 16:07 GMT
Originally opened as r-lib/devtools#1342


In utils.R, for read_dcf, the code is:

read_dcf <- function(path) {
  fields <- colnames(read.dcf(path))
  as.list(read.dcf(path, keep.white = fields)[1, ])
}

I wanted to know what the expected behavior would/should be for a DESCRIPTION with duplicated fields (for example Remotes): silent, warning, or error? If all = TRUE on read.dcf, this may allow for this case to be parsed with all remotes (even conflicting), but it may be a bad case and needs an error

Parsing DESCRIPTION with default read.dcf

url = "https://raw.githubusercontent.com/muschellij2/freesurfer/7f336cddadfa1000f128db3341893f96af9eaf51/DESCRIPTION"
destfile = file.path(tempdir(), "DESCRIPTION")
download.file(url, destfile = destfile)
dcf = read.dcf(destfile)
colnames(dcf)
##  [1] "Package"            "Type"               "Title"             
##  [4] "Version"            "Author"             "Maintainer"        
##  [7] "Description"        "Imports"            "Depends"           
## [10] "License"            "Suggests"           "VignetteBuilder"   
## [13] "Remotes"            "BugReports"         "SystemRequirements"
## [16] "RoxygenNote"

Only "last" Remotes section held

dcf[, "Remotes"]
##               Remotes 
## "neuroconductor/fslr"

Parsing DESCRIPTION with default read.dcf(all = TRUE)

dcf_all = read.dcf(destfile, all = TRUE)
colnames(dcf_all)
##  [1] "Package"            "Type"               "Title"             
##  [4] "Version"            "Author"             "Maintainer"        
##  [7] "Description"        "Imports"            "Depends"           
## [10] "License"            "Suggests"           "VignetteBuilder"   
## [13] "Remotes"            "BugReports"         "SystemRequirements"
## [16] "RoxygenNote"

All Remotes section held, but in a list now

dcf_all[, "Remotes"]
## [[1]]
## [1] "muschellij2/fslr,muschellij2/oro.nifti"
## [2] "neuroconductor/fslr"

Behavior from devtools

No error/warning was generated (as none was generated in read.dcf), but the "last" entry of the field (in this case "Remotes") was output:

dcf_dev = devtools:::read_dcf(destfile)
dcf_dev$Remotes
## [1] "Remotes: neuroconductor/fslr"

Feature Request: Find Minimum Version of Required Packages

Hello,

I'm trying to find the right home for this feature within the devtools universe... I initially submitted it at r-lib/devtools#1484. When I looked into the devtools diaspora, I think that this is the right place. Please let me know if you agree:

I've recently experienced an issue with my PKNCA package where I didn't know that a new feature I added had a minimum required version of a package in the Imports list. I'd like to propose a new feature of devtools that will take a list of packages and install them to look for the version number of dependencies where tests fail. It would then indicate that the next version is the required version.

A potential interface could be:

find_required_dep_version(pkg=".", which_set=c("Depends", "Imports", "Suggests"), which_library, repo=getOption("repos"), ...)

It would then search on CRAN (or potentially other repository types) installing dependency packages one-by-one back in time until tests fail.

If this would be of interest, I can generate a pull request.

Update imports environments on load_all

Would it make sense to update the imports environments of all loaded packages when a package is reloaded with load_all()? Currently these imports are scoped in a dangling namespace.

This is particularly problematic when .Call()ing dangling function pointers e.g. r-lib/testthat#654.

This could be solved by searching through all imports envs for all functions scoped in the package namespace and update their closure envs with the new namespace.

is_dev_package

Given name of package, returns TRUE or FALSE depending on whether or not it's been loaded by devtools.

Package S4 methods are sometimes not dispatched when using `load_all`

Issue by jonkeane
Monday Jun 05, 2017 at 19:53 GMT
Originally opened as r-lib/devtools#1522


I'm working on development of a few packages and we are using a number of S4 classes and methods. When using devtools' load_all() I've noticed that sometimes custom methods aren't being dispatched.

Here is a minimal example (I'm trying to write a new method for write.csv, and have that method pass all of it's arguments to another function, hence my use here.)
A package with the following in ./R/[anyfile].R:

new_class <- setClass("new_class", slots = c(text = 'character'))
setGeneric("write.csv")
setMethod("write.csv", "new_class", function (...)  print("using new_class method") )

When loaded with load_all() and trying to run the following:

new_obj <- new_class(text = 'foo')
write.csv(new_obj, file = 'bar')

Errors with (presumably because the standard write.csv method is being used):

Error in as.data.frame.default(x[[i]], optional = TRUE) : 
  cannot coerce class "structure("new_class", package = "test")" to a data.frame

Whereas, if I (install and) load the package with install() and run the same lines, I get what I expect:

new_obj <- new_class(text = 'foo')
write.csv(new_obj, file = 'bar')
[1] "using new_class method"

If I only provide new_obj and no other arguments my custom method is dispatched with both load_all() and install(), but I would like to be able to pass on arbitrary arguments with my custom method.

write.csv(new_obj)
[1] "using new_class method"

Because devtools' test() uses load_all(), I'm also seeing this behavior when I run tests through devtools as well. Running tests as part of R CMD check use the custom method just like if the package were installed / loaded with install().

?mypackage fails if mypackage is a documented function and package at the same time

Issue by benjaminweb
Friday Sep 30, 2016 at 19:55 GMT
Originally opened as r-lib/devtools#1358


devtools::create("mypackage")
cat("#' mypackage: some title\n#' Some description\n\"_PACKAGE\"\nNULL", file = "./mypackage/R/mypackage.R")
cat("#' Some function\nmypackage <- function(x) { print('bbbb')}", file = "./mypackage/R/functions.R")
devtools::document('./mypackage')
?mypackage
Using development documentation for mypackage
Error: length(filename) == 1L is not TRUE
In addition: Warning message:
In if (file == "") { :
  the condition has length > 1 and only the first element will be used

As I understand it, it is okay to name a function after the package's name.
How do I preview both help pages in development mode?

Methods reexported from another package with exportMethods() not available after load_all()

The RSQLite package now reexports all of DBI via explicit exportMethods() directives. For instance, dbGetQuery() is declared in DBI and not overridden in RSQLite, but still available from the RSQLite namespace after library(), but not with load_all():

library()

withr::with_dir(
  {dir.create(dir <- tempfile()); dir},
  {
    system("git clone https://github.com/rstats-db/RSQLite.git", intern = TRUE)
    withr::with_temp_libpaths({
      system("R CMD INSTALL RSQLite", intern = TRUE)
      library(RSQLite)
      dbGetQuery
    })
  }
)
#> standardGeneric for "dbGetQuery" defined from package "DBI"
#> 
#> function (conn, statement, ...) 
#> standardGeneric("dbGetQuery")
#> <environment: 0x5640fd8de5e0>
#> Methods may be defined for arguments: conn, statement
#> Use  showMethods("dbGetQuery")  for currently available ones.

load_all()

withr::with_dir(
  {dir.create(dir <- tempfile()); dir},
  {
    system("git clone https://github.com/rstats-db/RSQLite.git", intern = TRUE)
    pkgload::load_all("RSQLite", quiet = TRUE)
    dbGetQuery
  }
)
#> Error in force(code): object 'dbGetQuery' not found

Recompile everything when file in subfolder has changed

That would be useful for unity builds. The rlang C sources are now in a subfolder (https://github.com/tidyverse/rlang/tree/master/src/rlang) and the C files are included from a single file https://github.com/tidyverse/rlang/blob/master/src/rlang.c.

This has several advantages:

  • it is easy to copy that subfolder within another package
  • the entire compilation happens in a single compilation unit. This is less verbose (which is nicer when there are many files) and much faster.
  • including from a master C file is easier than defining a makefile.

However changing a file in a subfolder doesn't trigger a recompilation because the files it contains are not tracked for changes. @hadley suggested to always recompile when a subfolder file changes.

The overhead of recompiling everything shouldn't be an issue since unity builds are fast. Also this shouldn't affect most packages because using subfolders is rare.

check_dep_version should check all dependencies and report all issues (or none)

Issue by billdenney
Wednesday Jul 20, 2016 at 16:25 GMT
Originally opened as r-lib/devtools#1270


When loading or checking a package having many dependencies, check_dep_version only reports the first missing dependency and then stops. If there are multiple missing dependencies, it will lead to an inefficient cycle of load, install, load, ...

It would be helpful if there were a different command used like check_dep_versions(...) (note pluralization) that ran all the tests, returned TRUE if there were no errors, and reported all errors if there were any.

If interested, I'd be happy to contribute a patch that does this.

`dev_help` fails to find type="html" help, even when type="text" exists...

Issue by stevenpollack
Monday Jan 04, 2016 at 23:32 GMT
Originally opened as r-lib/devtools#1008


A reproducible example is available at this gist: https://gist.github.com/stevenpollack/141b14437c6c4b071fff#file-bestpracticeswalkthrough-r

Which I've been testing, with devtools:

devtools::source_gist('https://gist.github.com/stevenpollack/141b14437c6c4b071fff')

It outputs a warning message:

The file /var/folders/xv/zh9pr4x130x4grh_y77k11y00000gn/T//RtmpY7ToMU/Rtxt375e4af8cd54.html does not exist.

I suspect this has to do with the double // in the URI.

If you comment out line 109 and remove the comment on line 110, the help get's pulled up without any issues...

load_all unloading the dll too soon?

Maybe there is a bug in pkgload / devtools, in load_all(). I am trying to fix the processx reload crashes, and just noticed that load_all() does this:

  if (is_loaded(pkg) && is.null(dev_meta(pkg$package))) {
    # If installed version of package loaded, unload it
    # (and also the DLLs)
    unload(pkg, quiet = quiet)
  } else {
    # Unload only DLLs
    unload_dll(pkg)
  }

https://github.com/r-pkgs/pkgload/blob/764dcda25431012366f64bc4120ede589731aefc/R/load.r#L132-L139

This is before unloading the namespace (which triggers a cleanup in processx). Why would you want to unload the dll before the namespace?

Anyway, this causes crashes in repeated processx load_all() invocations, so it would be great to fix it.

Re-consider where helper files are sourced in load_all()

Issue by berndbischl
Thursday Apr 14, 2016 at 15:13 GMT
Originally opened as r-lib/devtools#1146


Your NEWS state this

load_all() now sources all test helpers if you use testthat. This makes it much easier to interactively run tests (#1125). load_all() also correctly handles unix and windows subdirectories within R (@gaborcsardi, #1102)

In my setup I have a helper.R file, in tests/testthat which creates a few (data) objects I want to use in my unit tests (among other stuff).

You can reproduce the problem by creating a basically empty (but valid) package, then adding such a file under tests/testthat

data(Sonar, package = "mlbench")
x = Sonar

This now breaks, after the new devtools update

> load_all()
Loading minipkg
Error in eval(expr, envir, enclos) : object 'Sonar' not found

mlbench would usually be in my SUGGESTS (and I want it to be there) but even adding it to DEPENDS and adding and explicit call to library("mlbench") in the helper.R does not remove the problem.

This now breaks our complete devel workflow.

Any advice?

Quote (or otherwise style) package names

I'm corresponding with @mine-cetinkaya-rundel re: building some dev versions of a couple packages (usethis and dependencies). We encountered this warning:

> devtools::check()
Updating usethis documentation
Loading usethis
Error in (function (dep_name, dep_ver = NA, dep_compare = NA)  : 
  Dependency package spelling not available.

This indicates the R package spelling needs to be installed (although I will fix that!), but it's really easy to misread or misinterpret this message. Quoting or other styling of the package name would help.

Originates from this line:

warning("Dependency package ", dep_name, " not available.")

Tests failing on Windows

I wanted to make a small change to pkgload so I made a fresh fork and set up a project in RStudio 1.1.442 on Windows 10.

I ran devtools::testthat() before I started, and there were a number of problems. I also ran the tests on AppVeyor, and all but one disappeared, so the others may be due to trying to test pkgload from within an R session.

Problem One: Windows and its strange paths

This one showed up both on my machine and on AppVeyor:

test-namespace.r:157: failure: Environments have the correct attributes
`wd` not identical to attr(pkgenv, "path").
1/1 mismatches
x[1]: "C:\\Users\\User\\pkgload\\tests\\testthat\\testNamespace"
y[1]: "C:/Users/User/pkgload/tests/testthat/testNamespace"

Problem Two: failure to install testDllLoad

This one didn't happen on Appveyor. I tried to get more information by removing quiet=TRUE from the install.packages call in test-dll.R, but that caused the problem to disappear.

  running command '"C:/PROGRA~1/R/R-34~1.4/bin/x64/R" CMD INSTALL --no-multiarch -l "C:\Users\User\AppData\Local\Temp\Rtmp2XEmpM\devtools_test" "testDllLoad"' had status 1
Warning in install.packages :
  installation of package ‘testDllLoad’ had non-zero exit status

Full output below:

There were also a couple of warnings on top of the problems outlined above.

> devtools::test()
Loading pkgload
Testing pkgload
√ | OK F W S | Context
√ | 28       | Data [1.1 s]
√ | 15   1   | Dependencies [0.9 s]
--------------------------------------------------------------------------------
test-depend.r:27: warning: Packages in depends are required
‘pkgbuild’ namespace cannot be unloaded:
  namespace ‘pkgbuild’ is imported by ‘devtools’ so cannot be unloaded
--------------------------------------------------------------------------------
√ |  2       | DESCRIPTION checks
/ |  0       | Compiled DLLsWarning in install.packages :
  running command '"C:/PROGRA~1/R/R-34~1.4/bin/x64/R" CMD INSTALL --no-multiarch -l "C:\Users\User\AppData\Local\Temp\RtmpekaFt6\devtools_test" "testDllLoad"' had status 1
Warning in install.packages :
  installation of package ‘testDllLoad’ had non-zero exit status
x | 12 2 1   | Compiled DLLs [25.2 s]
--------------------------------------------------------------------------------
test-dll.r:17: warning: unload() unloads DLLs from packages loaded with library()
there is no package called ‘testDllLoad’

test-dll.r:17: failure: unload() unloads DLLs from packages loaded with library()
require(testDllLoad) isn't true.

test-dll.r:21: error: unload() unloads DLLs from packages loaded with library()
could not find function "nulltest"
1: expect_true(is.null(nulltest())) at C:\Users\User\pkgload/tests/testthat/test-dll.r:21
2: quasi_label(enquo(object), label)
3: eval_bare(get_expr(quo), get_env(quo))
--------------------------------------------------------------------------------
√ |  4       | examples [0.7 s]
√ |  6       | extract_lang
√ | 27       | help [2.6 s]
√ | 11   1   | Imports [1.2 s]
--------------------------------------------------------------------------------
test-imports.r:24: warning: Imported objects are copied to package environment
JIT automatically disabled when unloading the compiler.
--------------------------------------------------------------------------------
√ |  6       | Load: collate [0.6 s]
√ | 36       | Load hooks [1.4 s]
√ |  2       | Loading [0.4 s]
√ | 17       | Metadata [0.9 s]
x | 30 1     | Namespace [3.2 s]
--------------------------------------------------------------------------------
test-namespace.r:157: failure: Environments have the correct attributes
`wd` not identical to attr(pkgenv, "path").
1/1 mismatches
x[1]: "C:\\Users\\User\\pkgload\\tests\\testthat\\testNamespace"
y[1]: "C:/Users/User/pkgload/tests/testthat/testNamespace"
--------------------------------------------------------------------------------
√ |  4       | package [0.2 s]
√ |  1       | s4-export [0.5 s]
√ | 11       | s4-sort [0.3 s]
√ | 58       | s4-unload [2.8 s]
√ | 18       | shim [1.7 s]

== Results =====================================================================
Duration: 43.9 s

OK:       288
Failed:   3
Warnings: 3
Skipped:  0

load_all() and symbol registration

load_all()
tibble::tibble(x = 1)
load_all()
tibble::tibble(x = 1)
#>  Error in .Call(rlang_is_formulaish, x, scoped, lhs) : 
#> Incorrect number of arguments (3), expecting 58441936 for '

You'll need the github version of tibble installed, and a checked-out version of rlang.

I think the problem is related to symbol registration and namespaces because it doesn't happen when you call functions in rlang directly.

cc @lionel-

`run_examples` shouldn't pass `show` to `pkgload::run_example`

Issue by amcdavid
Friday Jan 27, 2017 at 16:18 GMT
Originally opened as r-lib/devtools#1449


pkgload::run_example lacks a show parameter (not sure if this is intentional or an oversight), but devtools::run_examples tries to pass this parameter via lapply nonetheless. This makes run_examples fail with the following:

Running 76 example files in devtools ------------------------------------------
Loading devtools
Error in FUN(X[[i]], ...) : unused argument (show = TRUE)
Loading devtools

Repex

$ git clone [email protected]:hadley/devtools.git

Cloning into 'devtools'...

$ cd devtools/
$ R
> run_examples()

Updating devtools documentation
Loading devtools
Updating roxygen version in /Users/amcdavid/Downloads/devtools/DESCRIPTION
Writing package_deps.Rd
Writing use_build_ignore.Rd
Writing use_readme_rmd.Rd
Writing install_svn.Rd
Writing install_version.Rd
Writing path.Rd
Writing reexports.Rd
Writing revdep_check.Rd
Writing devtools-deprecated.Rd
Running 76 example files in devtools ------------------------------------------
Loading devtools
Error in FUN(X[[i]], ...) : unused argument (show = TRUE)
Loading devtools

> sessionInfo()

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.2

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] devtools_1.12.0.9000 knitr_1.15.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 roxygen2_5.0.1 crayon_1.3.2
[4] digest_0.6.12 withr_1.0.2 rprojroot_1.2
[7] R6_2.2.0 jsonlite_1.2 backports_1.0.5
[10] git2r_0.18.0 magrittr_1.5 httr_1.2.1
[13] stringi_1.1.2 rstudioapi_0.6 testthat_1.0.2
[16] whisker_0.3-2 callr_1.0.0.9000 tools_3.3.2
[19] stringr_1.1.0 pkgload_0.0.0.9000 pkgbuild_0.0.0.9000
[22] memoise_1.0.0

improper devtools::document() with file names leading with "_"

Issue by alexWhitworth
Wednesday Aug 31, 2016 at 16:12 GMT
Originally opened as r-lib/devtools#1317


Related to issue no 989.

I also get error Error: Missing name at **_data-model_data.R**. This is solved via removing the leading "_" from the file name. If this is not a bug, file name guidelines should at least be provided in the documentation or vignettes.

R> devtools::document("callProjection")
... 
Error: Missing name at _data-model_data.R:19

(Or perhaps this is a standard naming convention problem with all *.R files that I am unaware of? I can't find documentation of this anywhere if that is the case.)

Avoid roxygen2 dependency

It is only needed for update_collate(), and maybe devtools can just call that directly before loading the package?

package help index failing after load_all

Steps to reproduce with pkgload itself:

> devtools::load_all('path/to/pkgload')
...
> help(package = "pkgload", help_type = "text")
Error in is.character(topic) : object 'topic_str' not found
> traceback()
11: stop(e)
10: value[[3L]](cond)
9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
8: tryCatchList(expr, classes, parentenv, handlers)
7: tryCatch(if (missE) ...elt(i) else eval(cl.i, envir = envir), 
       error = function(e) {
           e$call <- cl.i
           stop(e)
       })
6: withCallingHandlers(tryCatch(if (missE) ...elt(i) else eval(cl.i, 
       envir = envir), error = function(e) {
       e$call <- cl.i
       stop(e)
   }), warning = function(w) {
       w$call <- cl.i
       w
   })
5: stopifnot(is.character(topic), length(topic) == 1)
4: dev_topic_parse(topic, dev_packages)
3: dev_topic_find(topic, dev_packages)
2: dev_help(topic_str, package_str)
1: help(package = "pkgload", help_type = "text")

Expected behavior:

> library(pkgload)
> help(package = "pkgload", help_type = "text")

		Information on packagepkgloadDescription:

Package:          pkgload
Title:            Simulate Package Installation and Attach
Version:          1.0.0
....

could not find function

I have an internal function:

#' @keywords internal
#' @export
my_func <- function() {
  print("Hi!")
}

It's being called elsewhere:

#' @export
my_other_func <- function() {
  my_func()
}

When I run devtools::load_all() and call my_other_func, I am getting the following error:

Error in my_func () : 
  could not find function "my_func "

I've tried removing the @export tag and removing the @keywords internal tag from my_func, and running document to recreate the NAMESPACE, but nothing has worked. Am I missing something very basic here?

Warning about exported but not-in-namespace objects

This never happened before, perhaps related to #30?

withr::with_dir(
  {dir.create(dir <- tempfile()); dir},
  {
    system("git clone https://github.com/rstats-db/DBI.git", intern = TRUE)
    pkgload::load_all("DBI", quiet = TRUE)
  }
)
#> Warning in setup_ns_exports(pkg, export_all): Objects listed as exports,
#> but not present in namespace: show

Environment of helper functions

The environment of the functions defined in testthat helpers seems to be the package environment, not the namespace environment. Is this by design?

devtools::load_all("~/git/R/tibble")
#> Loading tibble
environment(output_file)
#> <environment: package:tibble>
#> attr(,"name")
#> [1] "package:tibble"
#> attr(,"path")
#> [1] "/home/muelleki/git/R/tibble"

This means that I can't currently use mockr::with_mock() in a function defined in a helper. No big deal, but took some time to find out.

(Currently pkgload::load_all() doesn't seem to run helpers for me...)

Can't load downstream packages after load_all()

Issue by pitakakariki
Monday Jan 25, 2016 at 00:43 GMT
Originally opened as r-lib/devtools#1045


In the working directory of a project based on a local fork of https://github.com/lme4/lme4:

> devtools::load_all()
Loading lme4
Loading required package: Matrix
> library(MEMSS)
Error: packagelme4required byMEMSScould not be found

The error is thrown from base::.getRequiredPackages2, because it can't work out the version of the package loaded by devtools::load_all. The function .findVersion is defined inside base::getRequiredPackages2:

    .findVersion <- function(pkg, lib.loc = NULL) {
        pfile <- system.file("Meta", "package.rds", package = pkg, 
            lib.loc = lib.loc)
        if (nzchar(pfile)) 
            as.numeric_version(readRDS(pfile)$DESCRIPTION["Version"])
    }

It's not finding package.rds, so it's returning NULL. This triggers the error here:

        current <- .findVersion(pkg, lib.loc)
        if (is.null(current)) 
            stop(gettextf("package %s required by %s could not be found", 
                sQuote(pkg), sQuote(pkgname)), call. = FALSE, 
                domain = NA)

Need a way to add shims to an already loaded package

For example, when developing a new package that creates an htmlwidget, if you do load_all() on your package, then when your code calls htmlwidgets::htmlwidget(), it will no longer work. because it calls system.file() on your package -- but it needs the shimmed version of system.file() for this to work.

This is the workaround I currently use:
https://gist.github.com/wch/c942335660dc6c96322f

It would be nice if there were an easier way to shim this function (and possibly others) in an already-loaded package.

Interpolate function with rlang

This should make things easier to read:

onload_assign("process_imports", {
  for1 <- wrap_inner_loop(
    extract_lang(body(loadNamespace), comp_lang, y = quote(for(i in nsInfo$imports) NULL), idx = 1:3)
  )
  for2 <- wrap_inner_loop(
    extract_lang(body(loadNamespace), comp_lang,
      y = quote(for(imp in nsInfo$importClasses) NULL),
      idx = 1:3)
  )
  for3 <- wrap_inner_loop(
    extract_lang(body(loadNamespace), comp_lang,
      y = quote(for(imp in nsInfo$importMethods) NULL),
      idx = 1:3)
  )

  process_imports <- function(pkg = ".") {
    package <- pkg$name
    vI <- ("tools" %:::% ".split_description")(("tools" %:::% ".read_description")(file.path(pkg$path, "DESCRIPTION")))$Imports
    nsInfo <- parse_ns_file(pkg)
    ns <- ns_env(pkg)
    lib.loc <- NULL

    !! for1
    !! for2
    !! for3
  }

  process_imports <- tidy_interp(process_imports)
  fn_env(process_imports) <- ns_env("pkgload")

  process_imports
})

Error in load_all when use setClassUnion with NULL

Issue by epurdom
Wednesday Jun 07, 2017 at 19:15 GMT
Originally opened as r-lib/devtools#1523


Hello,

This error has been reported in #657, #168, #240. All of those issues to devtools are closed issues, so I am opening a new issue with what I hope is a reproducible example. I am using R 3.4.0, devtools_1.13.2. It's also been mentioned in the issues of other packages (ropensci/datapack#23, epurdom/clusterExperiment#175)

The issue is that load_all fails with setClassUnion calls. In my case one of the members is NULL, which ropensci/datapack#23 believes to be the problem. And indeed, I do not get the problem on my minimal example if I keep only the setClassUnion call that doesn't involve NULL.

I create a package with a minimal R code with the following setClassUnion calls (see also package attached demoPackageLoadError.zip
)

setOldClass("dendrogram")
setClassUnion("dendrogramOrNULL",members=c("dendrogram", "NULL"))
setClassUnion("matrixOrNULL",members=c("matrix", "NULL"))
setClassUnion("matrixOrMissing",members=c("matrix", "missing"))
setClass(
  Class = "A",
  slots = list(
    myOtherSlot="matrix",
    myDendro = "dendrogramOrNULL",
    myMatrix = "matrixOrNULL"
    )
)

I install this package on my computer with R CMD INSTALL.

The following load_all command DOES work:

> setwd("~/Documents/RfunctionsGenerally/demoPackageLoadError/")
> library(devtools)
> load_all()
Loading demoPackageLoadError
> library(demoPackageLoadError)
> load_all()
Loading demoPackageLoadError
Warning message:
class "dendrogram" is defined (with package slot ‘demoPackageLoadError’) but no metadata object found to revise superClass information---not exported?  Making a copy in package ‘demoPackageLoadError’ 

However, the following commands (on a new R session) does NOT work. This is run within RStudio, but I have the same problem in R.app at the terminal. I would note that the error message I get has changed slightly since I updated to R 3.4. I was not previously getting the error about get0 but only the second error. (This is based solely on my memory from frequently seeing the error on my full package, but I haven't tried different R versions with this minimal example).

> library(demoPackageLoadError)
> library(devtools)
> load_all()
Loading demoPackageLoadError
Error in get0(cname, where, inherits = inherits) : 
  invalid 'envir' argument
 Show Traceback
 
 Rerun with Debug
 Error in setClassUnion("dendrogramOrNULL", members = c("dendrogram", "NULL")) : 
  unable to create union class:  could not set members "NULL" 

The above code does work if I keep only the "matrixOrMissing" class. It does not work once I add back in just the matrixOrNULL class (so its not because of the dendrogram class).

I would also note the first code above that I said works with my minimal example, actually fails on my full package (in github: epurdom/clusterExperiment ). I can't yet recreate the failure I see on my full package on the first set of code with this minimal example. But I am hoping that fixing one would fix the other.

However, if it is helpful, I think I used to be able to use that code for my full package like the above minimal example before I moved to R 3.4 -- at least I use to be able to get it to sometimes work for me in R 3.3 for my full package and now it never works. I didn't know at the time why sometimes it worked and sometimes it didn't, but now having systematically run this minimal example I'm guessing it worked sometimes depending on the order of calling of my packages. Now I can no longer use load_all in any way for my full package which finally prompted me to make a minimal example, systematically test it, and report!

Avoid reloading packages

Issue by gaborcsardi
Thursday Feb 09, 2017 at 15:41 GMT
Originally opened as r-lib/devtools#1458


More specifically, it would be great if a package request not to be unloaded/reloaded, or at least not its shared lib.

This is because some packages cannot be reloaded properly. This includes all packages that depend on libglib on Linux. libgtk also depends on libglib, so libgtk dependent packages cannot be reloaded, either. If these packages are unloaded, they typically leave some extra threads behind. If they are then reloaded, then they probably crash R.

I am not sure what the best way would be to indicate this in the package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.