From 0d6ff51ee1e9ab57d419b54bc2e5fbf50cf7053c Mon Sep 17 00:00:00 2001 From: kbvernon Date: Fri, 17 Nov 2023 13:44:37 -0700 Subject: [PATCH 01/18] extendr project template --- R/create_extendr_package.R | 100 +++++++++++++++++++++ inst/rstudio/templates/project/extendr.dcf | 40 +++++++++ 2 files changed, 140 insertions(+) create mode 100644 R/create_extendr_package.R create mode 100644 inst/rstudio/templates/project/extendr.dcf diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R new file mode 100644 index 00000000..04d6a8eb --- /dev/null +++ b/R/create_extendr_package.R @@ -0,0 +1,100 @@ + +#' Create a project for R package development with Rust +#' +#' @description +#' This function creates an R project directory for package development with Rust extensions. +#' The function can be called on an existing project; you will be asked before +#' any existing files are changed. +#' +#' @inheritParams use_extendr +#' @inheritParams usethis::create_package +#' @param usethis logical, should usethis be used to build package directory? +#' @param ... ignored +#' +#' @return Path to the newly created project or package, invisibly. +#' @keywords internal +#' +#' @examples +create_extendr_package <- function(path, + usethis = TRUE, + roxygen = TRUE, + check_name = TRUE, + crate_name = NULL, + lib_name = NULL, + edition = c("2021", "2018"), + ...){ + + # check if rust infrastructure is available + # rust_sitrep() + + # build package directory, but don't open yet! + if (!usethis) { + + dir.create(path, recursive = TRUE, showWarnings = FALSE) + + # generate header for INDEX file + header <- c( + paste0("Package: ", basename(path)), + "", + "WARNING:", + "The project build failed to generate the necessary R package files.", + "Please consider installing {usethis} with `install.packages('usethis')` and running", + "usethis::create_package(getwd()).", + "" + ) + + } else { + + usethis::create_package( + path, + fields = list(), + rstudio = TRUE, + roxygen, + check_name, + open = FALSE + ) + + # generate header for INDEX file + header <- c( + paste0("Package: ", basename(path)), + "", + "BUILD COMPLETE:", + "The project build successfully generated the necessary R package files.", + paste0("Roxygen: ", roxygen), + "" + ) + + } + + # add rust scaffolding to project dir + # hunch is that rstudio project text input widgets return empty strings + # when no value is given + use_extendr( + path, + crate_name = if (crate_name == "") NULL else crate_name, + lib_name = if (lib_name == "") NULL else lib_name, + quiet = TRUE, + overwrite = TRUE, + edition + ) + + text <- c( + "NOTE:", + "To use {rextendr} in any meaningful way, it is required that the user have", + "Rust and Cargo available on their local machine. To check your own machine", + "please run `rextendr::rust_sitrep()` in the console. This will provide a", + "detailed report of the current state of your Rust infrastructure, along", + "with some helpful advice about how to address any issues that may arise." + ) + + content <- paste( + paste(header, collapse = "\n"), + paste(text, collapse = "\n"), + sep = "\n" + ) + + writeLines(content, con = file.path(path, "INDEX")) + + return(invisible(path)) + +} diff --git a/inst/rstudio/templates/project/extendr.dcf b/inst/rstudio/templates/project/extendr.dcf new file mode 100644 index 00000000..1cb6fcb1 --- /dev/null +++ b/inst/rstudio/templates/project/extendr.dcf @@ -0,0 +1,40 @@ +Binding: create_extendr_package +Title: R package with extendr +Subtitle: Create an R package with Rust extensions. +Caption: Create an R package with Rust extensions. +OpenFiles: INDEX + +Parameter: usethis +Widget: CheckboxInput +Label: Use usethis to build project directory +Default: On +Position: left + +Parameter: roxygen +Widget: CheckboxInput +Label: Use roxygen2 to document package +Default: On +Position: left + +Parameter: check_name +Widget: CheckboxInput +Label: Check if package name is valid +Default: On +Position: left + +Parameter: crate_name +Widget: TextInput +Label: Rust crate name +Position: right + +Parameter: lib_name +Widget: TextInput +Label: Rust library name +Position: right + +Parameter: edition +Widget: SelectInput +Label: Rust edition +Fields: 2021, 2018 +Default: 2021 +Position: right From f101613468efb7875001ab898402da866c596de2 Mon Sep 17 00:00:00 2001 From: kbvernon Date: Sun, 19 Nov 2023 12:18:24 -0700 Subject: [PATCH 02/18] use `rlang::list2()` to handle rstudio project gui args --- R/create_extendr_package.R | 56 +++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index 04d6a8eb..4c2c7d5c 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -2,39 +2,36 @@ #' Create a project for R package development with Rust #' #' @description -#' This function creates an R project directory for package development with Rust extensions. -#' The function can be called on an existing project; you will be asked before -#' any existing files are changed. +#' This function creates an R project directory for package development +#' with Rust extensions. #' -#' @inheritParams use_extendr -#' @inheritParams usethis::create_package -#' @param usethis logical, should usethis be used to build package directory? -#' @param ... ignored +#' @param path a path to new directory +#' @param ... arguments passed on to `usethis::create_package()` and +#' `rextendr::use_extendr()` #' #' @return Path to the newly created project or package, invisibly. #' @keywords internal #' #' @examples -create_extendr_package <- function(path, - usethis = TRUE, - roxygen = TRUE, - check_name = TRUE, - crate_name = NULL, - lib_name = NULL, - edition = c("2021", "2018"), - ...){ - - # check if rust infrastructure is available - # rust_sitrep() +create_extendr_package <- function(path, ...){ + + args <- rlang::list2(...) + + # hunch is that rstudio project text input widgets return empty strings + # when no value is given, want to make sure it is NULL so `use_extendr()` + # handles it correctly + args <- lapply(args, \(x){ if (x == "") return(NULL) else return(x) }) + + # generate header for INDEX file + header <- paste0("Package: ", basename(path)) # build package directory, but don't open yet! - if (!usethis) { + if (!args[["usethis"]]) { dir.create(path, recursive = TRUE, showWarnings = FALSE) - # generate header for INDEX file header <- c( - paste0("Package: ", basename(path)), + header, "", "WARNING:", "The project build failed to generate the necessary R package files.", @@ -49,33 +46,30 @@ create_extendr_package <- function(path, path, fields = list(), rstudio = TRUE, - roxygen, - check_name, + roxygen = args[["roxygen"]], + check_name = args[["check_name"]], open = FALSE ) - # generate header for INDEX file header <- c( - paste0("Package: ", basename(path)), + header, "", "BUILD COMPLETE:", "The project build successfully generated the necessary R package files.", - paste0("Roxygen: ", roxygen), + paste0("Roxygen: ", args[["roxygen"]]), "" ) } # add rust scaffolding to project dir - # hunch is that rstudio project text input widgets return empty strings - # when no value is given use_extendr( path, - crate_name = if (crate_name == "") NULL else crate_name, - lib_name = if (lib_name == "") NULL else lib_name, + crate_name = args[["crate_name"]], + lib_name = args[["lib_name"]], quiet = TRUE, overwrite = TRUE, - edition + edition = args[["edition"]] ) text <- c( From 1d0a9c3be31aafbcebb1278e0e5b1ab8e241931e Mon Sep 17 00:00:00 2001 From: kbvernon Date: Sun, 19 Nov 2023 12:18:44 -0700 Subject: [PATCH 03/18] simplify text to fit in rstudio project gui --- inst/rstudio/templates/project/extendr.dcf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/rstudio/templates/project/extendr.dcf b/inst/rstudio/templates/project/extendr.dcf index 1cb6fcb1..61b6055c 100644 --- a/inst/rstudio/templates/project/extendr.dcf +++ b/inst/rstudio/templates/project/extendr.dcf @@ -6,19 +6,19 @@ OpenFiles: INDEX Parameter: usethis Widget: CheckboxInput -Label: Use usethis to build project directory +Label: Use usethis Default: On Position: left Parameter: roxygen Widget: CheckboxInput -Label: Use roxygen2 to document package +Label: Use roxygen2 Default: On Position: left Parameter: check_name Widget: CheckboxInput -Label: Check if package name is valid +Label: Validate package name Default: On Position: left From 837ee5fca7c046491d2bddb31e7a3ec0577a563d Mon Sep 17 00:00:00 2001 From: kbvernon Date: Mon, 20 Nov 2023 08:46:06 -0700 Subject: [PATCH 04/18] lint code --- R/create_extendr_package.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index 4c2c7d5c..a25bad9b 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -35,8 +35,8 @@ create_extendr_package <- function(path, ...){ "", "WARNING:", "The project build failed to generate the necessary R package files.", - "Please consider installing {usethis} with `install.packages('usethis')` and running", - "usethis::create_package(getwd()).", + "Please consider installing {usethis} with `install.packages('usethis')`", + "and running usethis::create_package(getwd()).", "" ) @@ -74,9 +74,9 @@ create_extendr_package <- function(path, ...){ text <- c( "NOTE:", - "To use {rextendr} in any meaningful way, it is required that the user have", - "Rust and Cargo available on their local machine. To check your own machine", - "please run `rextendr::rust_sitrep()` in the console. This will provide a", + "To use {rextendr} in any meaningful way, the user must have", + "Rust and Cargo available on their local machine. To check that you do,", + "please run `rextendr::rust_sitrep()`. This will provide a", "detailed report of the current state of your Rust infrastructure, along", "with some helpful advice about how to address any issues that may arise." ) From 676a56ae9ca0ef473ecfeb2a9b1d22a714db097c Mon Sep 17 00:00:00 2001 From: kbvernon Date: Mon, 20 Nov 2023 10:23:36 -0700 Subject: [PATCH 05/18] lint more --- R/create_extendr_package.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index a25bad9b..62813862 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -13,14 +13,18 @@ #' @keywords internal #' #' @examples -create_extendr_package <- function(path, ...){ +create_extendr_package <- function(path, ...) { args <- rlang::list2(...) # hunch is that rstudio project text input widgets return empty strings # when no value is given, want to make sure it is NULL so `use_extendr()` # handles it correctly - args <- lapply(args, \(x){ if (x == "") return(NULL) else return(x) }) + args <- lapply(args, \(x) { + + if (x == "") return(NULL) else return(x) + + } ) # generate header for INDEX file header <- paste0("Package: ", basename(path)) From 2f1457cb097456520785e93c7ab8a6c14ef7865d Mon Sep 17 00:00:00 2001 From: kbvernon Date: Mon, 20 Nov 2023 10:30:54 -0700 Subject: [PATCH 06/18] use `function(x)` instead of `\(x)` and drop curly braces --- R/create_extendr_package.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index 62813862..0987cdc3 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -20,11 +20,7 @@ create_extendr_package <- function(path, ...) { # hunch is that rstudio project text input widgets return empty strings # when no value is given, want to make sure it is NULL so `use_extendr()` # handles it correctly - args <- lapply(args, \(x) { - - if (x == "") return(NULL) else return(x) - - } ) + args <- lapply(args, function(x) if (x == "") return(NULL) else return(x)) # generate header for INDEX file header <- paste0("Package: ", basename(path)) From 808849058bc03fb3bfff060757ad48c41d5f28d0 Mon Sep 17 00:00:00 2001 From: kbvernon Date: Mon, 20 Nov 2023 13:50:13 -0700 Subject: [PATCH 07/18] update to error if `usethis` is not installed --- R/create_extendr_package.R | 58 ++++++++-------------- inst/rstudio/templates/project/extendr.dcf | 6 --- 2 files changed, 20 insertions(+), 44 deletions(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index 0987cdc3..26744219 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -15,6 +15,9 @@ #' @examples create_extendr_package <- function(path, ...) { + # error if usethis is not installed + rlang::check_installed("usethis") + args <- rlang::list2(...) # hunch is that rstudio project text input widgets return empty strings @@ -22,45 +25,15 @@ create_extendr_package <- function(path, ...) { # handles it correctly args <- lapply(args, function(x) if (x == "") return(NULL) else return(x)) - # generate header for INDEX file - header <- paste0("Package: ", basename(path)) - # build package directory, but don't open yet! - if (!args[["usethis"]]) { - - dir.create(path, recursive = TRUE, showWarnings = FALSE) - - header <- c( - header, - "", - "WARNING:", - "The project build failed to generate the necessary R package files.", - "Please consider installing {usethis} with `install.packages('usethis')`", - "and running usethis::create_package(getwd()).", - "" - ) - - } else { - - usethis::create_package( - path, - fields = list(), - rstudio = TRUE, - roxygen = args[["roxygen"]], - check_name = args[["check_name"]], - open = FALSE - ) - - header <- c( - header, - "", - "BUILD COMPLETE:", - "The project build successfully generated the necessary R package files.", - paste0("Roxygen: ", args[["roxygen"]]), - "" - ) - - } + usethis::create_package( + path, + fields = list(), + rstudio = TRUE, + roxygen = args[["roxygen"]], + check_name = args[["check_name"]], + open = FALSE + ) # add rust scaffolding to project dir use_extendr( @@ -72,6 +45,15 @@ create_extendr_package <- function(path, ...) { edition = args[["edition"]] ) + # generate header for INDEX file + header <- c( + paste0("Package: ", basename(path)), + "", + "BUILD COMPLETE:", + "The project build successfully generated the necessary R package files.", + "" + ) + text <- c( "NOTE:", "To use {rextendr} in any meaningful way, the user must have", diff --git a/inst/rstudio/templates/project/extendr.dcf b/inst/rstudio/templates/project/extendr.dcf index 61b6055c..b27578e3 100644 --- a/inst/rstudio/templates/project/extendr.dcf +++ b/inst/rstudio/templates/project/extendr.dcf @@ -4,12 +4,6 @@ Subtitle: Create an R package with Rust extensions. Caption: Create an R package with Rust extensions. OpenFiles: INDEX -Parameter: usethis -Widget: CheckboxInput -Label: Use usethis -Default: On -Position: left - Parameter: roxygen Widget: CheckboxInput Label: Use roxygen2 From 6c1a396092483ac14dd5f37d4f30100fc7a6ebc7 Mon Sep 17 00:00:00 2001 From: kbvernon Date: Tue, 21 Nov 2023 09:03:40 -0700 Subject: [PATCH 08/18] properly nullify empty string with `rlang` --- R/create_extendr_package.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index 26744219..878b1d81 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -23,7 +23,11 @@ create_extendr_package <- function(path, ...) { # hunch is that rstudio project text input widgets return empty strings # when no value is given, want to make sure it is NULL so `use_extendr()` # handles it correctly - args <- lapply(args, function(x) if (x == "") return(NULL) else return(x)) + nullify_empty_string <- function(x) { + if (rlang::is_string(x) && nzchar(x)) x else NULL + } + + args <- purrr::map(args, nullify_empty_string) # build package directory, but don't open yet! usethis::create_package( From 10a50cbae06399ff5bfde964ed2baab77fbbf9b3 Mon Sep 17 00:00:00 2001 From: kbvernon Date: Sun, 3 Dec 2023 16:03:36 -0700 Subject: [PATCH 09/18] add `%||% TRUE` to handle possible NULL values --- R/create_extendr_package.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index 878b1d81..0ef1a67f 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -34,8 +34,8 @@ create_extendr_package <- function(path, ...) { path, fields = list(), rstudio = TRUE, - roxygen = args[["roxygen"]], - check_name = args[["check_name"]], + roxygen = args[["roxygen"]] %||% TRUE, + check_name = args[["check_name"]] %||% TRUE, open = FALSE ) @@ -46,7 +46,7 @@ create_extendr_package <- function(path, ...) { lib_name = args[["lib_name"]], quiet = TRUE, overwrite = TRUE, - edition = args[["edition"]] + edition = args[["edition"]] %||% TRUE ) # generate header for INDEX file From 0f41744de010b49572b886119fd01f3f52158aca Mon Sep 17 00:00:00 2001 From: kbvernon Date: Sun, 3 Dec 2023 16:12:53 -0700 Subject: [PATCH 10/18] new test for `create_extendr_package()` --- .../testthat/_snaps/create_extendr_package.md | 48 +++++++++++++++++++ tests/testthat/test-create_extendr_package.R | 26 ++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tests/testthat/_snaps/create_extendr_package.md create mode 100644 tests/testthat/test-create_extendr_package.R diff --git a/tests/testthat/_snaps/create_extendr_package.md b/tests/testthat/_snaps/create_extendr_package.md new file mode 100644 index 00000000..c0d992f8 --- /dev/null +++ b/tests/testthat/_snaps/create_extendr_package.md @@ -0,0 +1,48 @@ +# create_extendr_package() creates an extendr package project correctly + + Code + rextendr:::create_extendr_package(path = dir, roxygen = TRUE, check_name = TRUE, + edition = "2021") + Message + v Setting active project to 'TEMPORARY_PACKAGE_PATH' + v Creating 'R/' + v Writing 'DESCRIPTION' + Output + Package: testCreateExtendrPackage + Title: What the Package Does (One Line, Title Case) + Version: 0.0.0.9000 + Authors@R (parsed): + * First Last [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.3 + Message + v Writing 'NAMESPACE' + v Writing 'testCreateExtendrPackage.Rproj' + v Adding '^testCreateExtendrPackage\\.Rproj$' to '.Rbuildignore' + v Adding '.Rproj.user' to '.gitignore' + v Adding '^\\.Rproj\\.user$' to '.Rbuildignore' + v Setting active project to '' + v Setting active project to 'TEMPORARY_PACKAGE_PATH' + v Adding '^src/\\.cargo$' to '.Rbuildignore' + +--- + + Code + cat_file("INDEX") + Output + Package: testCreateExtendrPackage + + BUILD COMPLETE: + The project build successfully generated the necessary R package files. + + NOTE: + To use {rextendr} in any meaningful way, the user must have + Rust and Cargo available on their local machine. To check that you do, + please run `rextendr::rust_sitrep()`. This will provide a + detailed report of the current state of your Rust infrastructure, along + with some helpful advice about how to address any issues that may arise. + diff --git a/tests/testthat/test-create_extendr_package.R b/tests/testthat/test-create_extendr_package.R new file mode 100644 index 00000000..eb0ccbbd --- /dev/null +++ b/tests/testthat/test-create_extendr_package.R @@ -0,0 +1,26 @@ +test_that("create_extendr_package() creates an extendr package project correctly", { + + skip_if_not_installed("usethis") + + # capture setup messages + withr::local_options(usethis.quiet = FALSE) + + dir <- local_temp_dir("testCreateExtendrPackage") + + scrubbed_string <- normalizePath(dir, winslash = "/") + + expect_snapshot( + rextendr:::create_extendr_package( + path = dir, + roxygen = TRUE, + check_name = TRUE, + edition = "2021" + ), + transform = function(lines) { + stringi::stri_replace_all_fixed(lines, scrubbed_string, "TEMPORARY_PACKAGE_PATH") + } + ) + + expect_snapshot(cat_file("INDEX")) + +}) From a08cea1528a72174a9cde4e204c43b1120e26931 Mon Sep 17 00:00:00 2001 From: kbvernon Date: Fri, 8 Dec 2023 09:18:13 -0700 Subject: [PATCH 11/18] explain what 'open' means in comment --- R/create_extendr_package.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index 0ef1a67f..9bdc709b 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -29,7 +29,8 @@ create_extendr_package <- function(path, ...) { args <- purrr::map(args, nullify_empty_string) - # build package directory, but don't open yet! + # build package directory, but don't start a new R session with + # it as the working directory! i.e., set `open = FALSE` usethis::create_package( path, fields = list(), From 7b7c44553f2b70484a2ff07f593419c2cb6a73ea Mon Sep 17 00:00:00 2001 From: kbvernon Date: Fri, 8 Dec 2023 09:19:43 -0700 Subject: [PATCH 12/18] do not create INDEX file in project directory --- R/create_extendr_package.R | 26 ---------------------- inst/rstudio/templates/project/extendr.dcf | 1 - 2 files changed, 27 deletions(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index 9bdc709b..d85584eb 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -50,32 +50,6 @@ create_extendr_package <- function(path, ...) { edition = args[["edition"]] %||% TRUE ) - # generate header for INDEX file - header <- c( - paste0("Package: ", basename(path)), - "", - "BUILD COMPLETE:", - "The project build successfully generated the necessary R package files.", - "" - ) - - text <- c( - "NOTE:", - "To use {rextendr} in any meaningful way, the user must have", - "Rust and Cargo available on their local machine. To check that you do,", - "please run `rextendr::rust_sitrep()`. This will provide a", - "detailed report of the current state of your Rust infrastructure, along", - "with some helpful advice about how to address any issues that may arise." - ) - - content <- paste( - paste(header, collapse = "\n"), - paste(text, collapse = "\n"), - sep = "\n" - ) - - writeLines(content, con = file.path(path, "INDEX")) - return(invisible(path)) } diff --git a/inst/rstudio/templates/project/extendr.dcf b/inst/rstudio/templates/project/extendr.dcf index b27578e3..1892f6b5 100644 --- a/inst/rstudio/templates/project/extendr.dcf +++ b/inst/rstudio/templates/project/extendr.dcf @@ -2,7 +2,6 @@ Binding: create_extendr_package Title: R package with extendr Subtitle: Create an R package with Rust extensions. Caption: Create an R package with Rust extensions. -OpenFiles: INDEX Parameter: roxygen Widget: CheckboxInput From 0421bd0a33e2e150a28c8569da94f29780e7efa2 Mon Sep 17 00:00:00 2001 From: kbvernon Date: Fri, 8 Dec 2023 09:58:30 -0700 Subject: [PATCH 13/18] remove testthat test that is now irrelevant --- .../testthat/_snaps/create_extendr_package.md | 48 ------------------- tests/testthat/test-create_extendr_package.R | 26 ---------- 2 files changed, 74 deletions(-) delete mode 100644 tests/testthat/_snaps/create_extendr_package.md delete mode 100644 tests/testthat/test-create_extendr_package.R diff --git a/tests/testthat/_snaps/create_extendr_package.md b/tests/testthat/_snaps/create_extendr_package.md deleted file mode 100644 index c0d992f8..00000000 --- a/tests/testthat/_snaps/create_extendr_package.md +++ /dev/null @@ -1,48 +0,0 @@ -# create_extendr_package() creates an extendr package project correctly - - Code - rextendr:::create_extendr_package(path = dir, roxygen = TRUE, check_name = TRUE, - edition = "2021") - Message - v Setting active project to 'TEMPORARY_PACKAGE_PATH' - v Creating 'R/' - v Writing 'DESCRIPTION' - Output - Package: testCreateExtendrPackage - Title: What the Package Does (One Line, Title Case) - Version: 0.0.0.9000 - Authors@R (parsed): - * First Last [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.3 - Message - v Writing 'NAMESPACE' - v Writing 'testCreateExtendrPackage.Rproj' - v Adding '^testCreateExtendrPackage\\.Rproj$' to '.Rbuildignore' - v Adding '.Rproj.user' to '.gitignore' - v Adding '^\\.Rproj\\.user$' to '.Rbuildignore' - v Setting active project to '' - v Setting active project to 'TEMPORARY_PACKAGE_PATH' - v Adding '^src/\\.cargo$' to '.Rbuildignore' - ---- - - Code - cat_file("INDEX") - Output - Package: testCreateExtendrPackage - - BUILD COMPLETE: - The project build successfully generated the necessary R package files. - - NOTE: - To use {rextendr} in any meaningful way, the user must have - Rust and Cargo available on their local machine. To check that you do, - please run `rextendr::rust_sitrep()`. This will provide a - detailed report of the current state of your Rust infrastructure, along - with some helpful advice about how to address any issues that may arise. - diff --git a/tests/testthat/test-create_extendr_package.R b/tests/testthat/test-create_extendr_package.R deleted file mode 100644 index eb0ccbbd..00000000 --- a/tests/testthat/test-create_extendr_package.R +++ /dev/null @@ -1,26 +0,0 @@ -test_that("create_extendr_package() creates an extendr package project correctly", { - - skip_if_not_installed("usethis") - - # capture setup messages - withr::local_options(usethis.quiet = FALSE) - - dir <- local_temp_dir("testCreateExtendrPackage") - - scrubbed_string <- normalizePath(dir, winslash = "/") - - expect_snapshot( - rextendr:::create_extendr_package( - path = dir, - roxygen = TRUE, - check_name = TRUE, - edition = "2021" - ), - transform = function(lines) { - stringi::stri_replace_all_fixed(lines, scrubbed_string, "TEMPORARY_PACKAGE_PATH") - } - ) - - expect_snapshot(cat_file("INDEX")) - -}) From ecafd2e9e8c4a7060815725c5ec335bd14cc44cf Mon Sep 17 00:00:00 2001 From: kbvernon Date: Fri, 8 Dec 2023 10:09:30 -0700 Subject: [PATCH 14/18] add `@noRd` to prevent doc from rendering --- R/create_extendr_package.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index d85584eb..99b77ebf 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -12,7 +12,7 @@ #' @return Path to the newly created project or package, invisibly. #' @keywords internal #' -#' @examples +#' @noRd create_extendr_package <- function(path, ...) { # error if usethis is not installed From ea7f1c062c93ad7b3a4d70116420a1eda02418bb Mon Sep 17 00:00:00 2001 From: kbvernon Date: Sat, 27 Jan 2024 10:53:48 -0700 Subject: [PATCH 15/18] add info about rstudio project template and suggest use of `rust_sitrep()` --- vignettes/package.Rmd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vignettes/package.Rmd b/vignettes/package.Rmd index 9d451e91..3900d73a 100644 --- a/vignettes/package.Rmd +++ b/vignettes/package.Rmd @@ -52,7 +52,11 @@ rextendr::use_extendr() #> • Please run `rextendr::document()` for changes to take effect. ``` -Now we are just one step away from calling Rust functions from R. As the message says, we need to run `rextendr::document()`. +For developers who use RStudio, we also provide a project template that will call `usethis::create_package()` and `rextendr::use_extendr()` for you. This is done using RStudio's **Create Project** command, which you can find on the global toolbar or in the File menu. Choose "New Directory" then select "R package with extendr." You can then fill out the details to match your preferences. + +Once you have the project directory setup, we strongly encourage you to run `rextendr::rust_sitrep()` in the console. This will provide a detailed report of the current state of your Rust infrastructure, along with some helpful advice about how to address any issues that may arise. + +Assuming we have a proper installation of Rust, we are just one step away from calling Rust functions from R. As the message above says, we need to run `rextendr::document()`. But, before moving forward, let's look at the files added. ## Package structure From 79f372bf71783c1aa739ba2689831ef91d90f531 Mon Sep 17 00:00:00 2001 From: kbvernon Date: Sat, 27 Jan 2024 10:54:32 -0700 Subject: [PATCH 16/18] add `create_extendr_package()` --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index f0c904a9..cc89595b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ * `use_extendr()` gets a new ability to overwrite existing rextendr templates (#292). * `use_extendr()` sets `publish = false` in the `[package]` section of the `Cargo.toml` (#297). * `use_extendr()` correctly handles calls with `path` not equal to `"."` (current folder), or when there is no active `{usethis}` project (#323). +* `create_extendr_package()` allows user to create project directory using RStudio's **Project Command**. (#321) # rextend 0.3.1 From 3f78641f025ad3e83c2f79235089dfa23421c804 Mon Sep 17 00:00:00 2001 From: kbvernon Date: Sat, 27 Jan 2024 12:45:54 -0700 Subject: [PATCH 17/18] run `devtools::document()` --- DESCRIPTION | 2 +- man/rextendr.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 68ecc894..1bfe0424 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -69,6 +69,6 @@ Config/testthat/edition: 3 Config/testthat/parallel: true Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 SystemRequirements: Rust 'cargo'; the crate 'libR-sys' must compile without error diff --git a/man/rextendr.Rd b/man/rextendr.Rd index f00705eb..f1419093 100644 --- a/man/rextendr.Rd +++ b/man/rextendr.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/rextendr.R \docType{package} \name{rextendr} -\alias{rextendr} \alias{rextendr-package} +\alias{rextendr} \title{Call Rust code from R using the 'extendr' Crate} \description{ The rextendr package implements functions to interface with Rust code from R. From cbdb5b6f70b0db27f3ec97123883231f8af308f5 Mon Sep 17 00:00:00 2001 From: kbvernon Date: Sat, 3 Feb 2024 10:47:47 -0700 Subject: [PATCH 18/18] fix title, inherit params from `usethis::create_package()`, and remove `return()` --- R/create_extendr_package.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/create_extendr_package.R b/R/create_extendr_package.R index 99b77ebf..abee654a 100644 --- a/R/create_extendr_package.R +++ b/R/create_extendr_package.R @@ -1,11 +1,11 @@ -#' Create a project for R package development with Rust +#' Create package that uses Rust #' #' @description #' This function creates an R project directory for package development #' with Rust extensions. #' -#' @param path a path to new directory +#' @inheritParams usethis::create_package #' @param ... arguments passed on to `usethis::create_package()` and #' `rextendr::use_extendr()` #' @@ -50,6 +50,6 @@ create_extendr_package <- function(path, ...) { edition = args[["edition"]] %||% TRUE ) - return(invisible(path)) + invisible(path) }