Learn R Programming

SimDesign (version 1.1)

Attach: Attach the simulation conditions for easier reference

Description

This function accepts the condition object used to indicate the design conditions and makes the variable names available in the environment from which it is called. This is useful primarily as a convenience function when you prefer to call the variable names in condition directly rather than indexing with condition$sample_size or with(condition, sample_size), for example.

Usage

Attach(condition)

Arguments

condition
a data.frame containing the condition names

Details

The behavior of this function is very similar to attach, however it is environment specific, and therefore only remains defined in a given function rather than in the Global Environment. Hence, this function is much safer to use than the attach, which incidentally should never be used in your code.

See Also

runSimulation, Generate

Examples

Run this code
## Not run: 
# 
# # does not use Attach()
# mygenerate <- function(condition, fixed_objects = NULL){
#     N1 <- condition$sample_sizes_group1
#     N2 <- condition$sample_sizes_group2
#     sd <- condition$standard_deviations
# 
#     group1 <- rnorm(N1)
#     group2 <- rnorm(N2, sd=sd)
#     dat <- data.frame(group = c(rep('g1', N1), rep('g2', N2)),
#                       DV = c(group1, group2))
#     dat
# }
# 
# # similar to above, but using the Attach() function instead of indexing
# mygenerate <- function(condition, fixed_objects = NULL){
#     Attach(condition)
#     N1 <- sample_sizes_group1
#     N2 <- sample_sizes_group2
#     sd <- standard_deviations
# 
#     group1 <- rnorm(N1)
#     group2 <- rnorm(N2, sd=sd)
#     dat <- data.frame(group = c(rep('g1', N1), rep('g2', N2)),
#                       DV = c(group1, group2))
#     dat
# }
# ## End(Not run)

Run the code above in your browser using DataLab