Skip to content

Commit 118afa1

Browse files
committed
add convient behaviour for Attach()
1 parent 2b4093d commit 118afa1

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: SimDesign
22
Title: Structure for Organizing Monte Carlo Simulation Designs
3-
Version: 1.14.2
3+
Version: 1.14.3
44
Authors@R: c(person("Phil", "Chalmers", email = "[email protected]", role = c("aut", "cre"),
55
comment = c(ORCID="0000-0001-5332-2810")),
66
person("Matthew", "Sigal", role = c("ctb")),

R/Attach.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#' variables with the same names as in \code{condition}? Default is \code{TRUE}, which will avoid
1919
#' this error
2020
#'
21+
#' @param attach_listone_length logical; if the elemement to be assign is a list of length one
22+
#' then assign the first element of this list with the associated name. This generally avoids
23+
#' adding an often unnecessary list 1 index, such as \code{name <- list[[1L]]}
24+
#'
2125
#' @seealso \code{\link{runSimulation}}, \code{\link{Generate}}
2226
#' @references
2327
#' Sigal, M. J., & Chalmers, R. P. (2016). Play it again: Teaching statistics with Monte
@@ -57,14 +61,20 @@
5761
#' DV = c(group1, group2))
5862
#' dat
5963
#' }
64+
#'
6065
#' }
61-
Attach <- function(condition, check = TRUE){
66+
Attach <- function(condition, check = TRUE, attach_listone_length = TRUE){
6267
envir <- as.environment(-1L)
6368
if(check)
6469
if(any(ls(envir = envir) %in% names(condition)))
6570
stop(sprintf('Using Attach() will mask the previously defined variable(s): %s)',
6671
ls(envir = envir)[ls(envir = envir) %in% names(condition)]), call. = FALSE)
67-
for(n in names(condition))
72+
for(n in names(condition)){
73+
if(attach_listone_length && is.list(condition[[n]]) && length(condition[[n]]) == 1L){
74+
assign(n, condition[[n]][[1L]], envir = envir)
75+
next
76+
}
6877
assign(n, condition[[n]], envir = envir)
78+
}
6979
invisible()
7080
}

man/Attach.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)