Skip to content

Commit

Permalink
update to error if usethis is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
kbvernon committed Nov 20, 2023
1 parent 2f1457c commit 8088490
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 44 deletions.
58 changes: 20 additions & 38 deletions R/create_extendr_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,25 @@
#' @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
# 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))

# 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(
Expand All @@ -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",
Expand Down
6 changes: 0 additions & 6 deletions inst/rstudio/templates/project/extendr.dcf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8088490

Please sign in to comment.