Design <- createDesign(N1=c(10,20),
N2=c(10,20),
sd=c(1,2))
Design
# does not use Attach()
Generate <- function(condition, fixed_objects ) {
# condition = single row of Design input (e.g., condition <- Design[1,])
N1 <- condition$N1
N2 <- condition$N2
sd <- condition$sd
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
Generate <- function(condition, fixed_objects ) {
Attach(condition) # N1, N2, and sd are now 'attached' and visible
group1 <- rnorm(N1)
group2 <- rnorm(N2, sd=sd)
dat <- data.frame(group = c(rep('g1', N1), rep('g2', N2)),
DV = c(group1, group2))
dat
}
#####################
# NOTE: if you're using RStudio with code diagnostics on then evaluate + add the
# following output to your source file to manually support the flagged variables
Attach(Design, RStudio_flags=TRUE)
# Below is the same example, however with false positive missing variables suppressed
# when # !diagnostics ... is added added to the source file(s)
# !diagnostics suppress=N1,N2,sd
Generate <- function(condition, fixed_objects ) {
Attach(condition) # N1, N2, and sd are now 'attached' and visible
group1 <- rnorm(N1)
group2 <- rnorm(N2, sd=sd)
dat <- data.frame(group = c(rep('g1', N1), rep('g2', N2)),
DV = c(group1, group2))
dat
}
Run the code above in your browser using DataLab