usethis icon indicating copy to clipboard operation
usethis copied to clipboard

fix use_dependency when already LinkingTo

Open mpadge opened this issue 3 years ago • 0 comments

This PR is one way to resolve an error that arises when following @jimhester's advice on "Getting started with cpp11", which simply says to add a "LinkingTo" statement. cpp11 has a few other idiosyncracies in current form, so I sensibly tried usethis::use_cpp11() in case I'd missed a file or something. This is the result:

d <- file.path (tempdir (), "junk")
dir.create (d)
usethis::create_package (path = d, check_name = FALSE)
#> ✔ Writing 'NAMESPACE'
#> ✔ Setting active project to '<no active project>'
desc <- c (readLines (file.path (d, "DESCRIPTION")),
           "LinkingTo: cpp11")
writeLines (desc, file.path (d, "DESCRIPTION"))
setwd (d)
usethis::use_cpp11 ()
#> ✔ Setting active project to '/tmp/RtmpQGi7ct/junk'
#> ✔ Creating 'src/'
#> ✔ Adding '*.o', '*.so', '*.dll' to 'src/.gitignore'
#> ● Copy and paste the following lines into 'R/junk-package.R':
#>   ## usethis namespace: start
#>   #' @useDynLib junk, .registration = TRUE
#>   ## usethis namespace: end
#>   NULL
#> Error in if (delta < 0) {: argument is of length zero

Created on 2021-01-14 by the reprex package (v0.3.0)

Clearly happens because use_dependency did not envision a situation where setdiff(existing_type, "LinkingTo") returned empty. min_version remains NULL, so this change simply ensures that use_dependency does nothing in this case, instead of erroring.

mpadge avatar Jan 14 '21 09:01 mpadge