benmarwick / rrtools

rrtools: Tools for Writing Reproducible Research in R
Other
670 stars 85 forks source link

use_analysis: incorrect parsing of Suggests fields onto DESCRIPTION #96

Closed annakrystalli closed 4 years ago

annakrystalli commented 4 years ago

Please wait for some discussion of your report before making a Pull Request.

Describe the bug When running use_analysis, the DESCRIPTION file is not correctly populated with suggested packages. Instead what I get is:

Imports: bookdown
Suggests1: devtools
Suggests2: git2r

Tracing the error back through the source code I found that add_desc_package() does not vectorise well over a vector of packages supplied to name (ie c("devtools", "git2r")), hence the awkward behaviour.

To Reproduce

create_compendium("~/Desktop/test") and then open the `DESCRIPTION file to see error.

Expected behavior I would expect the following output instead:

Imports: bookdown
Suggests: devtools,
     git2r

The simplest way I can see to address the issue is to use lapply to vectorise the function over each suggested package. I'm making a short PR to that effect with added tests to check for it.

devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.0 (2019-04-26)
#>  os       macOS Mojave 10.14.3        
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_GB.UTF-8                 
#>  ctype    en_GB.UTF-8                 
#>  tz       Europe/London               
#>  date     2019-09-09                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.6.0)
#>  backports     1.1.4   2019-04-10 [1] CRAN (R 3.6.0)
#>  callr         3.3.1   2019-07-18 [1] CRAN (R 3.6.0)
#>  cli           1.1.0   2019-03-19 [1] CRAN (R 3.6.0)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.6.0)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 3.6.0)
#>  devtools      2.2.0   2019-09-07 [1] CRAN (R 3.6.0)
#>  digest        0.6.20  2019-07-04 [1] CRAN (R 3.6.0)
#>  DT            0.8     2019-08-07 [1] CRAN (R 3.6.0)
#>  ellipsis      0.2.0.1 2019-07-02 [1] CRAN (R 3.6.0)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 3.6.0)
#>  fs            1.3.1   2019-05-06 [1] CRAN (R 3.6.0)
#>  glue          1.3.1   2019-03-12 [1] CRAN (R 3.6.0)
#>  highr         0.8     2019-03-20 [1] CRAN (R 3.6.0)
#>  htmltools     0.3.6   2017-04-28 [1] CRAN (R 3.6.0)
#>  htmlwidgets   1.3     2018-09-30 [1] CRAN (R 3.6.0)
#>  knitr         1.24    2019-08-08 [1] CRAN (R 3.6.0)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 3.6.0)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.6.0)
#>  pkgbuild      1.0.5   2019-08-26 [1] CRAN (R 3.6.0)
#>  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.6.0)
#>  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.6.0)
#>  processx      3.4.1   2019-07-18 [1] CRAN (R 3.6.0)
#>  ps            1.3.0   2018-12-21 [1] CRAN (R 3.6.0)
#>  R6            2.4.0   2019-02-14 [1] CRAN (R 3.6.0)
#>  Rcpp          1.0.2   2019-07-25 [1] CRAN (R 3.6.0)
#>  remotes       2.1.0   2019-06-24 [1] CRAN (R 3.6.0)
#>  rlang         0.4.0   2019-06-25 [1] CRAN (R 3.6.0)
#>  rmarkdown     1.15    2019-08-21 [1] CRAN (R 3.6.0)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.6.0)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.6.0)
#>  stringi       1.4.3   2019-03-12 [1] CRAN (R 3.6.0)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.6.0)
#>  testthat      2.2.1   2019-07-25 [1] CRAN (R 3.6.0)
#>  usethis       1.5.1   2019-07-04 [1] CRAN (R 3.6.0)
#>  withr         2.1.2   2018-03-15 [1] CRAN (R 3.6.0)
#>  xfun          0.9     2019-08-21 [1] CRAN (R 3.6.0)
#>  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.6.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library

Created on 2019-09-09 by the reprex package (v0.3.0)

nevrome commented 4 years ago

Thank you for the observation and the PR!

The fix is fine, but maybe this is a good opportunity to get rid of add_desc_package. A solution with with the desc package would probably be more fancy. And reliable. What do you think, @annakrystalli and @benmarwick?

annakrystalli commented 4 years ago

While using the more formal desc sounds sensible, I just had a look at it and I'm not sure how mature/stable it is. Seems like tests are failing and some important issues not seeming to be adressed (eg https://github.com/r-lib/desc/issues/68). I guess as long as rrtools test are passing you can ensure it's doing what you want but I leave it up to your discretion whether desc is mature enough.

In any case, the reason I've spotted this is because I'm working on materials for a walkthrough of rrtools I'm doing on 2019-09-17 (next week) at the UK RSE conference. So would be great to have this bug sorted by then if possible.

benmarwick commented 4 years ago

Thanks for spotting this, it's my mistake for assuming add_desc_package() was vectorised without testing first! I think #97 is an excellent solution. I prefer not to add additional dependencies when we have a simple base fix like in this PR, so let's go ahead with that. I'm giving a full day workshop in this tomorrow in Japan, so I'm very grateful that you spotted this and made the PR! Hope your walkthough goes well @annakrystalli!

annakrystalli commented 4 years ago

Ooooh good luck tomorrow!!