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

Assign .Depends to package environment to mimic more closely to library() #61

Merged
merged 6 commits into from
Jan 20, 2018

Conversation

yiufung
Copy link
Contributor

@yiufung yiufung commented Jan 6, 2018

  • Change introduced

In load_all, assign .Depends to package environment, following the behavior in R attachNamespace(), as shown in R-3-4-3/src/library/base/R/namespace.R#L165.

  • Problems & Previous Workaround

It caused some issues that depend on this behavior, for example, using data.table within test_that.

Previously, the workarounds are:

  1. add .datatable.aware = TRUE (or other code) to package source file to make it data.table-aware. This is because data.table#cedta check failed at L32 and we had to assign manually to make L37 work. See data.table#2053, devtools#192, dplyr#548,
  2. manually change both DESCRIPTION/Imports and NAMESPACE. Not a preferred way as we all use roxygen2 to auto-generate NAMESPACE now, and to avoid that we had to add #' @import data.table directive in R code instead, which is no more convenient than 1).

The pain point is that we cannot use data.table within our package during dev phase. @mattdowle proposed 2 ways at answer. The ii) way ( 2) above) works for dev phase, but it requires source code changed. The i) way works only after package development is finished and when user uses library() to attach the package, so it's not convenient during development.

This commit enables:

  1. Only DESCRIPTION/Depends declaration is required, no R code change needed, keeping package source clean
  2. Works during package development phase, so devtools::test() works
  3. Mimicks even more closely to native library() behavior

image

With current pkgload:
image

image

With modified pkgload:
image

image

R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Traditional)_Hong Kong SAR.950  LC_CTYPE=Chinese (Traditional)_Hong Kong SAR.950   
[3] LC_MONETARY=Chinese (Traditional)_Hong Kong SAR.950 LC_NUMERIC=C                                       
[5] LC_TIME=Chinese (Traditional)_Hong Kong SAR.950    

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

other attached packages:
[1] pkgload_0.0.0.9000

loaded via a namespace (and not attached):
 [1] compiler_3.4.3        backports_1.1.2       magrittr_1.5          assertthat_0.2.0      R6_2.2.2              rprojroot_1.3-2      
 [7] tools_3.4.3           withr_2.1.1           rstudioapi_0.7.0-9000 yaml_2.1.16           crayon_1.3.4          desc_1.1.1           
[13] testthat_2.0.0        rlang_0.1.6.9002     

@jimhester
Copy link
Member

Thanks, this seems like a good improvement! I think we should include your skeleton package in the pkgload tests to prevent regressions.

Also if you could and note to NEWS.md describing the change, mentioning this issue number and your GitHub username.

Thanks again for the PR

@yiufung
Copy link
Contributor Author

yiufung commented Jan 6, 2018

It seems that library() reads from Meta/package.rds(link) to get Dependency info, which, when being packaged, actually ignores useless R dependency (see here), so I just add one more commit to follow the convention.

Result
image

@yiufung yiufung closed this Jan 6, 2018
@yiufung yiufung reopened this Jan 6, 2018
@yiufung
Copy link
Contributor Author

yiufung commented Jan 6, 2018

Tests added without including the whole skeleton package, just to avoid it becoming bulky. I think this is preventive enough. NEWS.md updated as well.

Travis Build failed twice due to poor network.. I'll do another PR close & reopen to re-trigger the build, which might make the thread a little messy. Hope you don't mind.

@yiufung yiufung closed this Jan 6, 2018
@yiufung yiufung reopened this Jan 6, 2018
@yiufung
Copy link
Contributor Author

yiufung commented Jan 20, 2018

Any other concerns I could address?

@jimhester
Copy link
Member

No, it is good, thanks again!

@jimhester jimhester merged commit 1588349 into r-lib:master Jan 20, 2018
@yiufung
Copy link
Contributor Author

yiufung commented Jan 20, 2018

:P thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants