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

Bug with "@import"ed data packages #1424

Closed
russHyde opened this issue Jun 21, 2022 · 2 comments · Fixed by #1509
Closed

Bug with "@import"ed data packages #1424

russHyde opened this issue Jun 21, 2022 · 2 comments · Fixed by #1509
Labels
bug an unexpected problem or unintended behavior good first issue ❤️ good issue for first-time contributors

Comments

@russHyde
Copy link
Collaborator

To reproduce:

In RStudio File -> New Project -> New Directory -> R Package
Package name = "temptanic"

This adds a package skeleton with R/hello.R. Running lintr::lint_package() flags a single whitespace lint in hello.R (irrelevant to the issue)

Add an R script to the package that imports the {titanic} package (https://cran.r-project.org/web/packages/titanic/index.html).

# dummy-imports.R

#' @import titanic
#'
NULL

Delete the initial NAMESPACE
Document the package - we see import(titanic) in NAMESPACE

Lint the {temptanic} package:

lintr::lint_package()
.Error in data.frame(pkg = ns, fun = getNamespaceExports(ns), stringsAsFactors = FALSE) : 
  arguments imply differing number of rows: 1, 0

(The same thing happens whether or not {titanic} is added to {temptanic}::Imports or Suggests)

Note the following:

> getNamespaceExports("titanic")
character(0)

As such, data.frame(pkg = "titanic", fun = getNamespaceExports("titanic"), stringsAsFactors = FALSE) complains due to mismatched argument lengths.

@russHyde russHyde added bug an unexpected problem or unintended behavior good first issue ❤️ good issue for first-time contributors labels Jun 21, 2022
@russHyde
Copy link
Collaborator Author

Flagged with "good first issue".
For new contributors: any code changes should probably be tested from namespace_imports and you'd need to know how to mock "getNamespaceExports"

@IndrajeetPatil
Copy link
Collaborator

This is actually the same issue as #1503, and was fixed in #1509.

Here is a minimal reproducible example:

dir <- tempfile()
pkg <- usethis::create_package(dir, open = FALSE, rstudio = FALSE)
#> ✔ Creating '/var/folders/xr/v_vddzvs33q5wg7jv9mr__4h0000gn/T/RtmpIUx7xR/file8635186610ff/'
#> ✔ Setting active project to '/private/var/folders/xr/v_vddzvs33q5wg7jv9mr__4h0000gn/T/RtmpIUx7xR/file8635186610ff'
#> ✔ Creating 'R/'
#> ✔ Writing 'DESCRIPTION'
#> Package: file8635186610ff
#> Title: What the Package Does (One Line, Title Case)
#> Version: 0.0.0.9000
#> Authors@R (parsed):
#>     * First Last <first.last@example.com> [aut, cre] (YOUR-ORCID-ID)
#> Description: What the package does (one paragraph).
#> License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
#>     license
#> Encoding: UTF-8
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 7.2.1
#> ✔ Writing 'NAMESPACE'
#> ✔ Setting active project to '<no active project>'
setwd(pkg)
fs::dir_create("R")
writeLines(
  c("#' @import titanic", "NULL"), 
  "R/script.R"
)
devtools::document()
#> ℹ Updating file8635186610ff documentation
#> ℹ Loading file8635186610ff
#> Writing 'NAMESPACE'
readLines("NAMESPACE")
#> [1] "# Generated by roxygen2: do not edit by hand"
#> [2] ""                                            
#> [3] "import(titanic)"
devtools::install(quiet = TRUE)
lintr::lint_package()

Created on 2022-09-25 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.1 (2022-06-23)
#>  os       macOS Monterey 12.5.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Berlin
#>  date     2022-09-25
#>  pandoc   2.19.2 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package          * version    date (UTC) lib source
#>  brio               1.1.3      2021-11-30 [1] CRAN (R 4.2.0)
#>  cachem             1.0.6      2021-08-19 [1] CRAN (R 4.2.0)
#>  callr              3.7.2      2022-08-22 [1] CRAN (R 4.2.0)
#>  cli                3.4.1      2022-09-23 [1] CRAN (R 4.2.1)
#>  crayon             1.5.1      2022-03-26 [1] CRAN (R 4.2.0)
#>  cyclocomp          1.1.0      2016-09-10 [1] CRAN (R 4.2.0)
#>  desc               1.4.2      2022-09-08 [1] CRAN (R 4.2.1)
#>  devtools           2.4.4.9000 2022-09-22 [1] Github (r-lib/devtools@9e2793a)
#>  digest             0.6.29     2021-12-01 [1] CRAN (R 4.2.0)
#>  ellipsis           0.3.2      2021-04-29 [1] CRAN (R 4.2.0)
#>  evaluate           0.16       2022-08-09 [1] CRAN (R 4.2.1)
#>  fansi              1.0.3      2022-03-24 [1] CRAN (R 4.2.0)
#>  fastmap            1.1.0      2021-01-25 [1] CRAN (R 4.2.0)
#>  file8635186610ff * 0.0.0.9000 2022-09-25 [1] local
#>  fs                 1.5.2      2021-12-08 [1] CRAN (R 4.2.0)
#>  glue               1.6.2      2022-02-24 [1] CRAN (R 4.2.0)
#>  highr              0.9        2021-04-16 [1] CRAN (R 4.2.0)
#>  htmltools          0.5.3      2022-07-18 [1] CRAN (R 4.2.1)
#>  htmlwidgets        1.5.4      2021-09-08 [1] CRAN (R 4.2.0)
#>  httpuv             1.6.6      2022-09-08 [1] CRAN (R 4.2.1)
#>  knitr              1.40       2022-08-24 [1] CRAN (R 4.2.1)
#>  later              1.3.0      2021-08-18 [1] CRAN (R 4.2.0)
#>  lazyeval           0.2.2      2019-03-15 [1] CRAN (R 4.2.0)
#>  lifecycle          1.0.2      2022-09-09 [1] CRAN (R 4.2.1)
#>  lintr              3.0.1.9000 2022-09-25 [1] local
#>  magrittr           2.0.3      2022-03-30 [1] CRAN (R 4.2.0)
#>  memoise            2.0.1      2021-11-26 [1] CRAN (R 4.2.0)
#>  mime               0.12       2021-09-28 [1] CRAN (R 4.2.0)
#>  miniUI             0.1.1.1    2018-05-18 [1] CRAN (R 4.2.0)
#>  pillar             1.8.1      2022-08-19 [1] CRAN (R 4.2.1)
#>  pkgbuild           1.3.1      2021-12-20 [1] CRAN (R 4.2.0)
#>  pkgconfig          2.0.3      2019-09-22 [1] CRAN (R 4.2.0)
#>  pkgload            1.3.0      2022-06-27 [1] CRAN (R 4.2.0)
#>  prettyunits        1.1.1      2020-01-24 [1] CRAN (R 4.2.0)
#>  processx           3.7.0      2022-07-07 [1] CRAN (R 4.2.1)
#>  profvis            0.3.7      2020-11-02 [1] CRAN (R 4.2.0)
#>  promises           1.2.0.1    2021-02-11 [1] CRAN (R 4.2.0)
#>  ps                 1.7.1      2022-06-18 [1] CRAN (R 4.2.0)
#>  purrr              0.3.4      2020-04-17 [1] CRAN (R 4.2.0)
#>  R.cache            0.16.0     2022-07-21 [1] CRAN (R 4.2.0)
#>  R.methodsS3        1.8.2      2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo               1.25.0     2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils            2.12.0     2022-06-28 [1] CRAN (R 4.2.0)
#>  R6                 2.5.1.9000 2022-08-06 [1] Github (r-lib/R6@87d5e45)
#>  Rcpp               1.0.9      2022-07-08 [1] CRAN (R 4.2.1)
#>  remotes            2.4.2      2021-11-30 [1] CRAN (R 4.2.0)
#>  reprex             2.0.2      2022-08-17 [1] CRAN (R 4.2.1)
#>  rex                1.2.1      2021-11-26 [1] CRAN (R 4.2.0)
#>  rlang              1.0.6      2022-09-24 [1] CRAN (R 4.2.1)
#>  rmarkdown          2.16       2022-08-24 [1] CRAN (R 4.2.1)
#>  roxygen2           7.2.1      2022-07-18 [1] CRAN (R 4.2.1)
#>  rprojroot          2.0.3      2022-04-02 [1] CRAN (R 4.2.0)
#>  rstudioapi         0.14       2022-08-22 [1] CRAN (R 4.2.1)
#>  sessioninfo        1.2.2      2021-12-06 [1] CRAN (R 4.2.0)
#>  shiny              1.7.2      2022-07-19 [1] CRAN (R 4.2.1)
#>  stringi            1.7.8      2022-07-11 [1] CRAN (R 4.2.1)
#>  stringr            1.4.1      2022-08-20 [1] CRAN (R 4.2.1)
#>  styler             1.7.0.9002 2022-09-13 [1] local
#>  testthat           3.1.4.9000 2022-09-22 [1] Github (r-lib/testthat@81dfbed)
#>  tibble             3.1.8      2022-07-22 [1] CRAN (R 4.2.1)
#>  titanic            0.1.0      2015-08-31 [1] CRAN (R 4.2.0)
#>  urlchecker         1.0.1      2021-11-30 [1] CRAN (R 4.2.0)
#>  usethis            2.1.6      2022-05-25 [1] CRAN (R 4.2.0)
#>  utf8               1.2.2      2021-07-24 [1] CRAN (R 4.2.0)
#>  vctrs              0.4.1      2022-04-13 [1] CRAN (R 4.2.0)
#>  withr              2.5.0      2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun               0.33       2022-09-12 [1] CRAN (R 4.2.1)
#>  xml2               1.3.3      2021-11-30 [1] CRAN (R 4.2.0)
#>  xmlparsedata       1.0.5      2021-03-06 [1] CRAN (R 4.2.0)
#>  xtable             1.8-4      2019-04-21 [1] CRAN (R 4.2.0)
#>  yaml               2.3.5      2022-02-21 [1] CRAN (R 4.2.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior good first issue ❤️ good issue for first-time contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants