[mirror] Opinionated R package quickstart
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fixed some issues with setup and clarified scope

VisruthSK 3016c09d 44f2cf4b

+84 -60
+39 -26
R/bootstrapper.R
··· 2 2 #' 3 3 #' Create a package with some opinionated setup. 4 4 #' 5 - #' @param path Path where the package should be created. Defaults to `"."` 6 5 #' @param fields Named list of `DESCRIPTION` fields passed to 7 6 #' [usethis::create_package()]. See [usethis::use_description()] 8 - #' @param private Whether to create the GitHub repository as private. Defaults to `TRUE`. 9 7 #' @param setup_gha Whether to configure GitHub Actions setup. 10 8 #' @param setup_dependabot Whether to write a Dependabot configuration. 11 9 #' @param setup_AGENTS Whether to write a default AGENTS file. ··· 15 13 #' @return Invisibly returns `NULL`. 16 14 #' @export 17 15 bootstrapper <- function( 18 - path = ".", 19 16 fields = getOption( 20 17 "usethis.description", 21 18 list( ··· 29 26 ) 30 27 ) 31 28 ), 32 - private = TRUE, 33 29 setup_gha = TRUE, 34 30 setup_dependabot = TRUE, 35 31 setup_AGENTS = FALSE, 36 32 setup_precommit = TRUE, 37 33 ... 38 34 ) { 39 - create_package(path, fields, private, ...) 35 + create_package(fields, ...) 40 36 pkg_setup( 41 37 setup_gha = setup_gha, 42 38 setup_dependabot = setup_dependabot, ··· 48 44 49 45 #' Create a Package and Connect GitHub 50 46 #' 51 - #' Create a package, apply `.Rbuildignore` cleanup, prompt for a license, and 52 - #' connect the package to GitHub. 47 + #' Create a package in root, prompts for a license, cleans 48 + #' up build ignore file. 53 49 #' 54 50 #' @inheritParams bootstrapper 55 51 #' @return Invisibly returns `NULL`. 56 52 #' @export 57 53 create_package <- function( 58 - path = ".", 59 54 fields = getOption("usethis.description"), 60 - private = TRUE, 61 55 ... 62 56 ) { 63 - usethis::create_package(path = path, fields = fields, ...) 57 + usethis::create_package(path = ".", fields = fields, ...) 64 58 unlink("*.Rproj") 65 - find_replace_in_file( 66 - "^\\^.*\\\\\\.Rproj\\$$", 67 - "", 68 - ".Rbuildignore", 69 - fixed = FALSE 70 - ) 71 - find_replace_in_file( 72 - "^\\^\\\\\\.Rproj\\\\\\.user\\$$", 73 - "", 74 - ".Rbuildignore", 75 - fixed = FALSE 76 - ) 77 - readLines(".Rbuildignore", warn = FALSE) |> 78 - Filter(nzchar, x = _) |> 79 - writeLines(".Rbuildignore") 80 59 use_license() 81 - usethis::use_github(private = private) 60 + cleanup_buildignore() 82 61 invisible(NULL) 83 62 } 84 63 ··· 118 97 fs::path("NEWS.md") 119 98 ) 120 99 100 + # flags 121 101 if (setup_gha) { 122 102 setup_gha() 123 103 } ··· 131 111 setup_precommit() 132 112 } 133 113 114 + # cleanup 134 115 try_air_jarl_format() 135 116 usethis::use_tidy_description() 117 + cleanup_buildignore() 118 + 136 119 invisible(NULL) 137 120 } 138 121 ··· 246 229 setup_precommit <- function() { 247 230 copy_template_file("pre-commit", fs::path(".git", "hooks", "pre-commit")) 248 231 Sys.chmod(fs::path(".git", "hooks", "pre-commit"), mode = "0755") 232 + invisible(NULL) 233 + } 234 + 235 + #' Remove RStudio Project Ignore Entries 236 + #' 237 + #' Removes default RStudio project ignore patterns from `.Rbuildignore` and 238 + #' drops empty lines. 239 + #' 240 + #' @return Invisibly returns `NULL`. 241 + #' @keywords internal 242 + #' @noRd 243 + cleanup_buildignore <- function() { 244 + if (!file.exists(".Rbuildignore")) { 245 + return(invisible(NULL)) 246 + } 247 + find_replace_in_file( 248 + "^\\^.*\\\\\\.Rproj\\$$", 249 + "", 250 + ".Rbuildignore", 251 + fixed = FALSE 252 + ) 253 + find_replace_in_file( 254 + "^\\^\\\\\\.Rproj\\\\\\.user\\$$", 255 + "", 256 + ".Rbuildignore", 257 + fixed = FALSE 258 + ) 259 + readLines(".Rbuildignore", warn = FALSE) |> 260 + Filter(nzchar, x = _) |> 261 + writeLines(".Rbuildignore") 249 262 invisible(NULL) 250 263 } 251 264
+3 -3
README.md
··· 17 17 18 18 ## Usage 19 19 20 - The package is optimized for my usage by default, so calling the main function bare is not advised unless you are me. 20 + The package is optimized for my usage by default, so calling the main function bare is not advised unless you are me. You should call it in a directory which is already tracked by git and already has GitHub as a remote. 21 21 22 22 ```r 23 - bootstrapper:bootstrapper() 23 + bootstrapper::bootstrapper() 24 24 ``` 25 25 26 26 The main thing to set is the fields option, where you should put your own name, email, etc. instead. 27 27 28 28 ```r 29 - bootstrapper:bootstrapper( 29 + bootstrapper::bootstrapper( 30 30 fields = list( 31 31 "Authors@R" = person( 32 32 "Visruth",
-6
man/bootstrapper.Rd
··· 5 5 \title{Bootstrap a New R Package} 6 6 \usage{ 7 7 bootstrapper( 8 - path = ".", 9 8 fields = getOption("usethis.description", list(`Authors@R` = person("Visruth", 10 9 "Srimath Kandali", , "public@visruth.com", role = c("aut", "cre", "cph"), comment = 11 10 c(ORCID = "0009-0005-9097-0688")))), 12 - private = TRUE, 13 11 setup_gha = TRUE, 14 12 setup_dependabot = TRUE, 15 13 setup_AGENTS = FALSE, ··· 18 16 ) 19 17 } 20 18 \arguments{ 21 - \item{path}{Path where the package should be created. Defaults to \code{"."}} 22 - 23 19 \item{fields}{Named list of \code{DESCRIPTION} fields passed to 24 20 \code{\link[usethis:create_package]{usethis::create_package()}}. See \code{\link[usethis:use_description]{usethis::use_description()}}} 25 - 26 - \item{private}{Whether to create the GitHub repository as private. Defaults to \code{TRUE}.} 27 21 28 22 \item{setup_gha}{Whether to configure GitHub Actions setup.} 29 23
+3 -12
man/create_package.Rd
··· 4 4 \alias{create_package} 5 5 \title{Create a Package and Connect GitHub} 6 6 \usage{ 7 - create_package( 8 - path = ".", 9 - fields = getOption("usethis.description"), 10 - private = TRUE, 11 - ... 12 - ) 7 + create_package(fields = getOption("usethis.description"), ...) 13 8 } 14 9 \arguments{ 15 - \item{path}{Path where the package should be created. Defaults to \code{"."}} 16 - 17 10 \item{fields}{Named list of \code{DESCRIPTION} fields passed to 18 11 \code{\link[usethis:create_package]{usethis::create_package()}}. See \code{\link[usethis:use_description]{usethis::use_description()}}} 19 - 20 - \item{private}{Whether to create the GitHub repository as private. Defaults to \code{TRUE}.} 21 12 22 13 \item{...}{Additional arguments passed to \code{\link[usethis:create_package]{usethis::create_package()}}.} 23 14 } ··· 25 16 Invisibly returns \code{NULL}. 26 17 } 27 18 \description{ 28 - Create a package, apply \code{.Rbuildignore} cleanup, prompt for a license, and 29 - connect the package to GitHub. 19 + Create a package in root, prompts for a license, cleans 20 + up build ignore file. 30 21 }
+39 -13
tests/testthat/test-bootstrapper.R
··· 2 2 calls <- character() 3 3 4 4 testthat::local_mocked_bindings( 5 - create_package = function(path, fields, private, ...) { 5 + create_package = function(fields, ...) { 6 6 calls <<- c(calls, "create_package") 7 - expect_identical(path, "pkg") 8 7 expect_identical(fields, list(name = "value")) 9 - expect_false(private) 10 8 expect_identical(list(...), list(open = FALSE)) 11 9 NULL 12 10 }, ··· 28 26 29 27 expect_null( 30 28 bootstrapper::bootstrapper( 31 - path = "pkg", 32 29 fields = list(name = "value"), 33 - private = FALSE, 34 30 setup_gha = FALSE, 35 31 setup_dependabot = FALSE, 36 32 setup_precommit = FALSE, ··· 60 56 seen$create <<- list(path = path, fields = fields, dots = list(...)) 61 57 NULL 62 58 }, 63 - use_github = function(private) { 64 - seen$private <<- private 65 - NULL 66 - }, 67 59 .package = "usethis" 68 60 ) 69 61 ··· 77 69 78 70 expect_null( 79 71 bootstrapper::create_package( 80 - path = "pkg", 81 72 fields = fields, 82 - private = FALSE, 83 73 open = FALSE 84 74 ) 85 75 ) 86 76 87 - expect_identical(seen$create$path, "pkg") 77 + expect_identical(seen$create$path, ".") 88 78 expect_identical(seen$create$fields, fields) 89 79 expect_identical(seen$create$dots, list(open = FALSE)) 90 80 expect_false(file.exists("pkg.Rproj")) 91 81 expect_identical(readLines(".Rbuildignore", warn = FALSE), "keep") 92 - expect_false(seen$private) 93 82 expect_true(isTRUE(seen$license)) 94 83 }) 95 84 ··· 418 407 fs::path(".git", "hooks", "pre-commit") 419 408 ) 420 409 expect_identical(captured$chmod$mode, "0755") 410 + }) 411 + 412 + test_that("cleanup_buildignore removes Rproj entries and empty lines", { 413 + tmp <- tempfile("bootstrapper-buildignore-") 414 + dir.create(tmp) 415 + old <- setwd(tmp) 416 + on.exit(setwd(old), add = TRUE) 417 + 418 + cleanup_buildignore <- getFromNamespace( 419 + "cleanup_buildignore", 420 + "bootstrapper" 421 + ) 422 + 423 + writeLines( 424 + c("^.*\\.Rproj$", "^\\.Rproj\\.user$", "keep-this", ""), 425 + ".Rbuildignore" 426 + ) 427 + 428 + expect_null(cleanup_buildignore()) 429 + expect_identical(readLines(".Rbuildignore", warn = FALSE), "keep-this") 430 + }) 431 + 432 + test_that("cleanup_buildignore keeps unrelated entries", { 433 + tmp <- tempfile("bootstrapper-buildignore-") 434 + dir.create(tmp) 435 + old <- setwd(tmp) 436 + on.exit(setwd(old), add = TRUE) 437 + 438 + cleanup_buildignore <- getFromNamespace( 439 + "cleanup_buildignore", 440 + "bootstrapper" 441 + ) 442 + 443 + writeLines(c("foo", "bar", ""), ".Rbuildignore") 444 + 445 + expect_null(cleanup_buildignore()) 446 + expect_identical(readLines(".Rbuildignore", warn = FALSE), c("foo", "bar")) 421 447 }) 422 448 423 449 test_that("pkg_setup rethrows a generic message when test setup fails", {