Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make double dot work with mcapply #59

Closed
assignUser opened this issue Oct 3, 2020 · 2 comments
Closed

make double dot work with mcapply #59

assignUser opened this issue Oct 3, 2020 · 2 comments

Comments

@assignUser
Copy link
Collaborator

as mentioned in #41 thie does not work but should:

  #--- this doesn't work but is how I like to do things

myreplicate <- function(x, def) {
  age_effect <- x
  genData(2, def)
}

lapply(c(0, 5, 10), function(x) myreplicate(x, def))
#> [[1]]
#>    id age agemult
#> 1:  1  10     100
#> 2:  2  10     100
#> 
#> [[2]]
#>    id age agemult
#> 1:  1  10     100
#> 2:  2  10     100
#> 
#> [[3]]
#>    id age agemult
#> 1:  1  10     100
#> 2:  2  10     100
@assignUser
Copy link
Collaborator Author

@kgoldfeld this has to do with environments, I will look into how to maybe find way to solve this differntly but for now you can just use <<- for the assignment and it works:

library(simstudy)
def <- defData(varname = "age", formula=10, dist = "nonrandom")
def <- defData(def,
    varname = "agemult",
    formula = "age * ..age_effect", dist = "nonrandom"
)

myreplicate <- function(x, def) {
  age_effect <<- x
  genData(2, def)
}

lapply(c(0, 5, 10), function(x) myreplicate(x, def))
#> [[1]]
#>    id age agemult
#> 1:  1  10       0
#> 2:  2  10       0
#> 
#> [[2]]
#>    id age agemult
#> 1:  1  10      50
#> 2:  2  10      50
#> 
#> [[3]]
#>    id age agemult
#> 1:  1  10     100
#> 2:  2  10     100

Created on 2020-10-03 by the reprex package (v0.3.0.9001)

@assignUser
Copy link
Collaborator Author

maybe explaining this trick for simulations would be somethign for the double dot vignette #52

@assignUser assignUser changed the title male double dot work with mcapply make double dot work with mcapply Oct 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant