Skip to content

Commit

Permalink
feat: unpack and assign functions added
Browse files Browse the repository at this point in the history
  • Loading branch information
dnldelarosa committed Oct 2, 2023
1 parent 927091b commit 8cfc347
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
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.2.1
Version: 0.3.0
Authors@R:
person(given = "Daniel E.",
family = "de la Rosa",
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

export("%...>%")
export("%<...%")
export("%>%")
export("%T>%")
export(":=")
Expand Down
28 changes: 28 additions & 0 deletions R/unpack_assign.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@

#' 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
if (.warn) {
Expand Down Expand Up @@ -34,6 +47,21 @@



#' 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)
}
30 changes: 30 additions & 0 deletions man/grapes-...-greater-than-grapes.Rd

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

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

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

0 comments on commit 8cfc347

Please sign in to comment.