From f1a769262018c29ada77574bcd1a1cad076df1b2 Mon Sep 17 00:00:00 2001 From: "Daniel E. de la Rosa" Date: Sat, 14 Oct 2023 19:23:56 -0400 Subject: [PATCH] doc: describe example and unpkg assign unexported --- .Rbuildignore | 3 +- DESCRIPTION | 2 +- NAMESPACE | 3 +- R/cut3.R | 2 +- R/describe.R | 8 +-- R/pins.R | 4 +- R/ts_tci.R | 2 + R/unpack_assign.R | 70 +++++++++++++++------------ man/cut3.Rd | 2 +- man/describe.Rd | 6 ++- man/grapes-...-greater-than-grapes.Rd | 30 ------------ man/grapes-less-than-...-grapes.Rd | 28 ----------- 12 files changed, 58 insertions(+), 102 deletions(-) delete mode 100644 man/grapes-...-greater-than-grapes.Rd delete mode 100644 man/grapes-less-than-...-grapes.Rd diff --git a/.Rbuildignore b/.Rbuildignore index 7f25173..0dda87b 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,4 +10,5 @@ ^\.travis\.yml$ ^CODE_OF_CONDUCT\.md$ test.Rmd -^temp$ \ No newline at end of file +^temp$ +^showcase$ diff --git a/DESCRIPTION b/DESCRIPTION index 1d36738..f7d4a96 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Dmisc Title: Daniel miscellaneous functions -Version: 0.3.0 +Version: 0.3.1 Authors@R: person(given = "Daniel E.", family = "de la Rosa", diff --git a/NAMESPACE b/NAMESPACE index 35b9d85..db968fa 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,12 +1,11 @@ # Generated by roxygen2: do not edit by hand -export("%...>%") -export("%<...%") export("%>%") export("%T>%") export(":=") export(cut3) export(cut3_quantile) +export(describe) export(vars_to_date) importFrom(lifecycle,deprecate_soft) importFrom(lifecycle,deprecate_warn) diff --git a/R/cut3.R b/R/cut3.R index 2619c7d..62a50f9 100644 --- a/R/cut3.R +++ b/R/cut3.R @@ -10,7 +10,7 @@ #' @param groups [character]: The name of the variable for grouping data before conversion. #' @param bf_args [list]: Additional arguments to be passed to the break function. #' @param .inf [logical]: Whether to extend break points with -Inf and Inf. -#' @param ...: Additional arguments passed to \code{\link[base:cut]{base::cut}}. +#' @param ... Additional arguments passed to \code{\link[base:cut]{base::cut}}. #' #' @seealso #' \code{\link[base:cut]{base::cut}}, for the underlying cut function used. diff --git a/R/describe.R b/R/describe.R index 1f8f65a..f70d7bb 100644 --- a/R/describe.R +++ b/R/describe.R @@ -12,13 +12,15 @@ #' #' @return A table containing summary statistics for each variable in the data frame #' -#' +#' @export #' #' @examples -#' \dontrun{ +#' # Using summary +#' summary(cars) +#' +#' # Using describe #' describe(cars, flextable = TRUE) #' describe(cars, flextable = TRUE, ft_args = list(cwidth = 1)) -#' } describe <- function(data, digits = 4, t = TRUE, flextable = FALSE, ft_args = list(), ...) { data <- as.data.frame(data) res <- list() diff --git a/R/pins.R b/R/pins.R index 044d89c..690244f 100644 --- a/R/pins.R +++ b/R/pins.R @@ -21,6 +21,8 @@ pin_get_or_create <- function(.data, .board, .name, type = 'csv', ...) { .versions <- character() .version <- NULL + . <- NULL + created <- NULL tryCatch( { .versions <- pins::pin_versions(.board, .name)[['version']] @@ -42,7 +44,7 @@ pin_get_or_create <- function(.data, .board, .name, type = 'csv', ...) { .versions <- pins::pin_versions(.board, .name) .version <- .versions %>% dplyr::arrange(created) %>% - tail(1) %>% + utils::tail(1) %>% dplyr::pull(version) %>% .[[1]] } diff --git a/R/ts_tci.R b/R/ts_tci.R index 8237b80..643d446 100644 --- a/R/ts_tci.R +++ b/R/ts_tci.R @@ -1,4 +1,6 @@ ts_tc <- function(.ts, .vars = NULL, .type = c('i', 'p', 'c'), .base = 1){ + tc <- NULL + year <- NULL .names <- names(ts_to_df(.ts)) .names <- ifelse(is.null(.vars), .names[.names != 'date'], .vars) .type <- ifelse(length(.type) > 1, .type[[1]], .type) diff --git a/R/unpack_assign.R b/R/unpack_assign.R index b33b75a..fbaa537 100644 --- a/R/unpack_assign.R +++ b/R/unpack_assign.R @@ -1,19 +1,38 @@ -#' Unpack and assign values to specified names in an environment -#' `r lifecycle::badge("experimental")` -#' -#' @param names A character vector specifying the names of variables to be assigned. -#' @param values A list or vector containing the values to be assigned to the names. -#' @param .envir The environment where the variables will be assigned. Defaults to the global environment. -#' @param .warn Logical flag indicating whether to show a warning message. Defaults to TRUE. -#' -#' @return NULL. The function performs assignments in the specified environment. -#' @export -#' -#' @examples -#' c("x", "y") %<...% list(1, 2) -`%<...%` <- function(names, values, .envir = .GlobalEnv, .warn = TRUE) { - # Emitir una advertencia si 'warn' es TRUE +# Unpack and assign values to specified names in an environment +# `r lifecycle::badge("experimental")` +# +# @param names A character vector specifying the names of variables to be assigned. +# @param values A list or vector containing the values to be assigned to the names. +# @param ... Additional arguments, including +# \itemize{ +# \item{.envir}{The environment where the variables will be assigned. Defaults to the global environment.} +# \item{.warn}{Logical flag indicating whether to show a warning message. Defaults to TRUE.} +# } +# +# @return NULL. The function performs assignments in the specified environment. +# +# +# @rdname unpkg-assign +# +# @examples +# \dontrun{ +# c("x", "y") %<...% list(1, 2) +# } +`%<...%` <- function(names, values, ...) { + # Collect additional arguments + args <- list(...) + + # Set default values if not provided + if (is.null(args[['.envir']])){ + .envir <- .GlobalEnv + } + + if (is.null(args[['.warn']])){ + .warn <- TRUE + } + + # Issue a warning if '.warn' is TRUE if (.warn) { warning("This function assigns variables to the global environment by default. ", "This may overwrite existing objects. To assign to a different environment, ", @@ -47,21 +66,8 @@ -#' Wrapper around `%<...%` to unpack and assign values to specified names in an environment -#' `r lifecycle::badge("experimental")` -#' -#' @param values A list or vector containing the values to be assigned to the names. -#' @param names A character vector specifying the names of variables to be assigned. -#' @param .envir The environment where the variables will be assigned. Defaults to the global environment. -#' @param .warn Logical flag indicating whether to show a warning message. Defaults to TRUE. -#' -#' @return NULL. The function performs assignments in the specified environment. -#' @export -#' -#' @examples -#' values <- list(1, 2) -#' names <- c("x", "y") -#' values %...>% names -`%...>%` <- function(values, names, .envir = .GlobalEnv, .warn = TRUE) { - `%<...%`(names, values, .envir = .envir, .warn = .warn) +# @rdname unpkg-assign +# @order 2 +`%...>%` <- function(values, names, ...) { + `%<...%`(names, values, ...) } diff --git a/man/cut3.Rd b/man/cut3.Rd index ed969d4..905e7bf 100644 --- a/man/cut3.Rd +++ b/man/cut3.Rd @@ -20,7 +20,7 @@ cut3(tbl, var_name, breaks, groups = NULL, bf_args = list(), .inf = FALSE, ...) \item{.inf}{\link{logical}: Whether to extend break points with -Inf and Inf.} -\item{...:}{Additional arguments passed to \code{\link[base:cut]{base::cut}}.} +\item{...}{Additional arguments passed to \code{\link[base:cut]{base::cut}}.} } \value{ A data frame identical to the input \code{tbl}, with \code{var_name} converted to a factor. diff --git a/man/describe.Rd b/man/describe.Rd index 3ac8107..f85568e 100644 --- a/man/describe.Rd +++ b/man/describe.Rd @@ -27,8 +27,10 @@ A table containing summary statistics for each variable in the data frame This function generates a summary table for a data frame, containing summary statistics for each variable in the data frame. } \examples{ -\dontrun{ +# Using summary +summary(cars) + +# Using describe describe(cars, flextable = TRUE) describe(cars, flextable = TRUE, ft_args = list(cwidth = 1)) } -} diff --git a/man/grapes-...-greater-than-grapes.Rd b/man/grapes-...-greater-than-grapes.Rd deleted file mode 100644 index 56e58c1..0000000 --- a/man/grapes-...-greater-than-grapes.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/unpack_assign.R -\name{\%...>\%} -\alias{\%...>\%} -\title{Wrapper around \verb{\%<...\%} to unpack and assign values to specified names in an environment -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}} -\usage{ -values \%...>\% names -} -\arguments{ -\item{values}{A list or vector containing the values to be assigned to the names.} - -\item{names}{A character vector specifying the names of variables to be assigned.} - -\item{.envir}{The environment where the variables will be assigned. Defaults to the global environment.} - -\item{.warn}{Logical flag indicating whether to show a warning message. Defaults to TRUE.} -} -\value{ -NULL. The function performs assignments in the specified environment. -} -\description{ -Wrapper around \verb{\%<...\%} to unpack and assign values to specified names in an environment -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} -} -\examples{ -values <- list(1, 2) -names <- c("x", "y") -values \%...>\% names -} diff --git a/man/grapes-less-than-...-grapes.Rd b/man/grapes-less-than-...-grapes.Rd deleted file mode 100644 index 8050b8c..0000000 --- a/man/grapes-less-than-...-grapes.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/unpack_assign.R -\name{\%<...\%} -\alias{\%<...\%} -\title{Unpack and assign values to specified names in an environment -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}} -\usage{ -names \%<...\% values -} -\arguments{ -\item{names}{A character vector specifying the names of variables to be assigned.} - -\item{values}{A list or vector containing the values to be assigned to the names.} - -\item{.envir}{The environment where the variables will be assigned. Defaults to the global environment.} - -\item{.warn}{Logical flag indicating whether to show a warning message. Defaults to TRUE.} -} -\value{ -NULL. The function performs assignments in the specified environment. -} -\description{ -Unpack and assign values to specified names in an environment -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} -} -\examples{ -c("x", "y") \%<...\% list(1, 2) -}