Closed Robinlovelace closed 2 years ago
Interesting, how did you create the package folder? I get the first error at usethis::use_description()
.
Can you provide a minimum reproducible example? I assume your steps were
usethis::use_description()
rextendr::use_extendr()
Also, it could be nice if you can provide your version of R
, {usethis}
and {extednr}
, e.g.
> R.version$version.string
> installed.packages()[c("usethis", "rextendr"), "Version"]
Thanks for the quick responses. All you need to do to reproduce the error, I think, is run the following command to create a project:
rstudioapi::openProject("test")
Please try it and let me know how you get on. In terms of package versions, see below.
R.version$version.string
#> [1] "R version 4.1.2 (2021-11-01)"
installed.packages()[c("usethis", "rextendr"), "Version"]
#> usethis rextendr
#> "2.1.5" "0.2.0.9000"
Created on 2022-02-15 by the reprex package (v2.0.1)
Here's a reprex:
library(usethis)
library(rextendr)
path <- file.path(tempdir(), "my.pkg")
dir.create(path)
setwd(path)
proj_set(path, force = TRUE)
#> ✓ Setting active project to '/private/var/folders/
#> w7/8yv1j00s0bb3pfhmqc_rvd980000gn/T/RtmpfgerYV/my.pkg'
use_description()
#> ✓ Writing 'DESCRIPTION'
#> Package: my.pkg
#> 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.1.2
rextendr::use_extendr()
#> ✓ Creating 'src/rust/src'.
#> ✓ Writing 'src/entrypoint.c'
#> ✓ Writing 'src/Makevars'
#> ✓ Writing 'src/Makevars.win'
#> ✓ Writing 'src/.gitignore'
#> ✓ Writing 'src/rust/Cargo.toml'.
#> ✓ Writing 'src/rust/src/lib.rs'
#> ✓ Writing 'R/extendr-wrappers.R'
#> Warning in file(path, open = file_mode, encoding = "utf-8"): cannot open file
#> '/private/var/folders/w7/8yv1j00s0bb3pfhmqc_rvd980000gn/T/RtmpfgerYV/my.pkg/R/
#> extendr-wrappers.R': No such file or directory
#> Error in file(path, open = file_mode, encoding = "utf-8"): cannot open the connection
Created on 2022-02-15 by the reprex package (v2.0.1)
Creating R/
fixes it, and we should definitely deal with a lack of that directory:
library(usethis)
library(rextendr)
path <- file.path(tempdir(), "my.pkg")
dir.create(path)
setwd(path)
proj_set(path, force = TRUE)
#> Omitted
use_description()
#> Omitted
dir.create("R")
rextendr::use_extendr()
#> ✓ Creating 'src/rust/src'.
#> ✓ Writing 'src/entrypoint.c'
#> ✓ Writing 'src/Makevars'
#> ✓ Writing 'src/Makevars.win'
#> ✓ Writing 'src/.gitignore'
#> ✓ Writing 'src/rust/Cargo.toml'.
#> ✓ Writing 'src/rust/src/lib.rs'
#> ✓ Writing 'R/extendr-wrappers.R'
#> ✓ Finished configuring extendr for package my.pkg.
#> • Please update the system requirement in 'DESCRIPTION' file.
#> • Please run `rextendr::document()` for changes to take effect.
Created on 2022-02-15 by the reprex package (v2.0.1)
That said, just running use_description()
in a project is not the usual workflow for generating a package. create_package()
does much more than just write a DESCRIPTION
file (and for good reason). While the devtools ecosystem will still treat a project with a DESCRIPTION
file as a package, you're missing out on the other legwork usethis does for you.
Great to see the reprex and can see the logic behind create_package()
. However, not everyone uses usethis
and flexibility is good. Related question: how would you use create_package()
to create the DESCRIPTION and the R folder (and other good stuff!) building on your reprex below:
library(usethis)
library(rextendr)
path <- file.path(tempdir(), "my.pkg")
dir.create(path)
setwd(path)
Asking because a common and I think reasonable workflow is to create the folder outside of R first, do some things, and then turn it into a package later down the line.
Not everyone uses usethis/devtools, but I think most people should use some sort of a template rather than remembering to set up all the structure themselves, e.g. with package.skeleton()
or something.
Anyway, this is a simplified version of what usethis does:
library(usethis)
library(rextendr)
path <- file.path(tempdir(), "my.pkg")
dir.create(path)
setwd(path)
proj_set(path, force = TRUE)
#> ✓ Setting active project to '/private/var/folders/qn/
#> mk0qm8552zlgst0bnn2374tm0000gn/T/RtmpJk1dZw/my.pkg'
use_description()
#> ✓ Writing 'DESCRIPTION'
#> Package: my.pkg
#> 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.1.2
use_namespace()
#> ✓ Writing 'NAMESPACE'
use_directory("R/")
#> ✓ Creating 'R/'
# optionally: use .Rproj
# use_rstudio()
use_extendr()
#> ✓ Creating 'src/rust/src'.
#> ✓ Writing 'src/entrypoint.c'
#> ✓ Writing 'src/Makevars'
#> ✓ Writing 'src/Makevars.win'
#> ✓ Writing 'src/.gitignore'
#> ✓ Writing 'src/rust/Cargo.toml'.
#> ✓ Writing 'src/rust/src/lib.rs'
#> ✓ Writing 'R/extendr-wrappers.R'
#> ✓ Finished configuring extendr for package my.pkg.
#> • Please update the system requirement in 'DESCRIPTION' file.
#> • Please run `rextendr::document()` for changes to take effect.
Created on 2022-02-15 by the reprex package (v2.0.1)
Of course, this is all a bit moot, since I obviously think we should just create R/
. I was just making the suggestion to you since you were using usethis in your example, and create_package()
is definitely the suggested workflow for creating packages with usethis
Ok, seems about right to manually create R/
folder. We indeed based our workflow on usethis::create_package()
, which usually starts with an empty R/
folder.
Hi guys, great package. Just a heads-up on my experience when using it in a new project, not sure what the error message was (I guess an R folder is needed) but could certainly be better error message:
Thanks!