Skip to content

Commit

Permalink
doc: describe example and unpkg assign unexported
Browse files Browse the repository at this point in the history
  • Loading branch information
dnldelarosa committed Oct 14, 2023
1 parent 8cfc347 commit f1a7692
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 102 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
^\.travis\.yml$
^CODE_OF_CONDUCT\.md$
test.Rmd
^temp$
^temp$
^showcase$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/cut3.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions R/describe.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion R/pins.R
Original file line number Diff line number Diff line change
Expand Up @@ -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']]
Expand All @@ -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]]
}
Expand Down
2 changes: 2 additions & 0 deletions R/ts_tci.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
70 changes: 38 additions & 32 deletions R/unpack_assign.R
Original file line number Diff line number Diff line change
@@ -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, ",
Expand Down Expand Up @@ -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, ...)
}
2 changes: 1 addition & 1 deletion man/cut3.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/describe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions man/grapes-...-greater-than-grapes.Rd

This file was deleted.

28 changes: 0 additions & 28 deletions man/grapes-less-than-...-grapes.Rd

This file was deleted.

0 comments on commit f1a7692

Please sign in to comment.