diff --git a/DESCRIPTION b/DESCRIPTION index 42c7822..3c7fc3f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,11 +11,9 @@ Depends: R (>= 2.10) Imports: cli, - fs, - readr, rlang Suggests: - purrr + usethis Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 5a7d0ca..6ae9268 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,3 +1,2 @@ # Generated by roxygen2: do not edit by hand -export(copy_standalone_script) diff --git a/R/copy_standalone_script.R b/R/copy_standalone_script.R deleted file mode 100644 index e02a017..0000000 --- a/R/copy_standalone_script.R +++ /dev/null @@ -1,50 +0,0 @@ -#' Copy Standalone Script -#' -#' Copy a standalone script from within this package or from the rlang -#' package into your local package. -#' -#' @param script (`string`)\cr -#' named of the script to copy. The names follow the pattern `-`. -#' Must be one of `r shQuote(names(standalone::lst_scripts))`. -#' See below for details. -#' @param destdir directory where the script will be saved. Default is `"./R"` -#' -#' @details -#' These are the standalone scripts available and their location. -#' -#' ```{r echo=FALSE} -#' standalone::lst_scripts |> -#' purrr::iwalk(~cat(.y,": ", .x, "\n", sep = "")) -#' ``` -#' -#' @return NULL -#' @export -#' -#' @examplesIf FALSE -#' copy_standalone_script("standalone-checks") -copy_standalone_script <- function(script, destdir = "./R") { - # get script alias - script_name <- rlang::arg_match(script, values = names(standalone::lst_scripts)) - destdir_and_filename <- fs::path(destdir, basename(standalone::lst_scripts[[script_name]])) - - # read script from GH - chr_script <- readr::read_lines(file = standalone::lst_scripts[[script_name]]) - - if (!fs::dir_exists(dirname(destdir))) { - cli::cli_abort("Destination directory {.path {destdir}} does not exist.") - } - - # check if file already exists - if (fs::file_exists(destdir_and_filename)) { - cli::cli_text("File {.path {destdir_and_filename}} already exists. Would you like to replace it?") - if (interactive()) { - response <- utils::menu(choices = c("Yes", "No")) - } - if (response == 2L || !interactive()) { - return(invisible()) - } - } - - # write script to local destination - readr::write_lines(chr_script, file = destdir_and_filename) -} diff --git a/R/standalone-checks.R b/R/standalone-checks.R index a7eef0b..fcb465c 100644 --- a/R/standalone-checks.R +++ b/R/standalone-checks.R @@ -110,7 +110,7 @@ check_scalar <- function(x, arg_name = rlang::caller_arg(x), call = parent.frame check_range <- function(x, range, include_bounds = c(FALSE, FALSE), - arg_name = caller_arg(x), + arg_name = rlang::caller_arg(x), scalar = FALSE, msg = paste( "The {.arg {arg_name}} argument must be in the interval", @@ -165,8 +165,8 @@ check_range <- function(x, #' @return invisible #' @keywords internal #' @noRd -check_binary <- function(x, arg_name = caller_arg(x), call = parent.frame()) { - if (!is.logical(x) && !(is_integerish(x) && is_empty(setdiff(x, c(0, 1, NA))))) { +check_binary <- function(x, arg_name = rlang::caller_arg(x), call = parent.frame()) { + if (!is.logical(x) && !(rlang::is_integerish(x) && rlang::is_empty(setdiff(x, c(0, 1, NA))))) { paste( "Expecting column {.arg {arg_name}} to be either {.cls logical}", "or {.cls {c('numeric', 'integer')}} coded as {.val {c(0, 1)}}." diff --git a/README.md b/README.md index 72b8621..7c913bd 100644 --- a/README.md +++ b/README.md @@ -5,24 +5,16 @@ [![R-CMD-check](https://github.com/ddsjoberg/standalone/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ddsjoberg/standalone/actions/workflows/R-CMD-check.yaml) -The goal of standalone is to provide standalone scripts that are useful for the -development of R packages. While you need to install this package to use the -interface to copy scripts into your package, the standalone package does not need to be a dependency of the package you are developing. +The goal of standalone is to provide standalone scripts that are useful for the development of R packages. +The standalone package **will not** be a dependency of the package you are developing. +You don't even need to install it to use the standalone scripts housed in this repo. -## Installation - -You can install **standalone** from [GitHub](https://github.com/) with: - -``` r -# install.packages("devtools") -devtools::install_github("ddsjoberg/standalone") -``` ## Example To copy a standalone script with useful checks against user inputs, run: ``` r -standalone::copy_standalone_script("standalone-checks") +usethis::use_standalone("ddsjoberg/standalone", file = "checks") ``` diff --git a/man/copy_standalone_script.Rd b/man/copy_standalone_script.Rd deleted file mode 100644 index 7d0d1ec..0000000 --- a/man/copy_standalone_script.Rd +++ /dev/null @@ -1,45 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/copy_standalone_script.R -\name{copy_standalone_script} -\alias{copy_standalone_script} -\title{Copy Standalone Script} -\usage{ -copy_standalone_script(script, destdir = "./R") -} -\arguments{ -\item{script}{(\code{string})\cr -named of the script to copy. The names follow the pattern \verb{-}. -Must be one of 'standalone-checks', 'standalone-stringr', 'standalone-forcats', 'rlang-purrr', 'rlang-cli', 'rlang-downstream-deps', 'rlang-lazyeval', 'rlang-lifecycle', 'rlang-linked-version', 'rlang-obj-type', 'rlang-s3-register', 'rlang-sizes', 'rlang-types-check', 'rlang-vctrs', 'rlang-zeallot'. -See below for details.} - -\item{destdir}{directory where the script will be saved. Default is \code{"./R"}} -} -\description{ -Copy a standalone script from within this package or from the rlang -package into your local package. -} -\details{ -These are the standalone scripts available and their location. - -\if{html}{\out{
}}\preformatted{#> standalone-checks: https://raw.githubusercontent.com/ddsjoberg/standalone/main/R/standalone-checks.R -#> standalone-stringr: https://raw.githubusercontent.com/ddsjoberg/standalone/main/R/standalone-stringr.R -#> standalone-forcats: https://raw.githubusercontent.com/ddsjoberg/standalone/main/R/standalone-forcats.R -#> rlang-purrr: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-purrr.R -#> rlang-cli: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-cli.R -#> rlang-downstream-deps: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-downstream-deps.R -#> rlang-lazyeval: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-lazyeval.R -#> rlang-lifecycle: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-lifecycle.R -#> rlang-linked-version: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-linked-version.R -#> rlang-obj-type: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-obj-type.R -#> rlang-s3-register: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-s3-register.R -#> rlang-sizes: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-sizes.R -#> rlang-types-check: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-types-check.R -#> rlang-vctrs: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-vctrs.R -#> rlang-zeallot: https://raw.githubusercontent.com/r-lib/rlang/main/R/standalone-zeallot.R -}\if{html}{\out{
}} -} -\examples{ -\dontshow{if (FALSE) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -copy_standalone_script("standalone-checks") -\dontshow{\}) # examplesIf} -}