Skip to content

Commit

Permalink
Merge pull request #233 from kgoldfeld/232-functions-used-in-formula=…
Browse files Browse the repository at this point in the history
…-argument-in-defdata-not-available-for-functions-defined-out-of-global-namespace

232 functions used in formula= argument in defdata not available for functions defined out of global namespace
  • Loading branch information
kgoldfeld authored Jul 29, 2024
2 parents 8ee0284 + 3adbd69 commit 89e852a
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 65 deletions.
64 changes: 59 additions & 5 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ message: 'To cite package "simstudy" in publications use:'
type: software
license: GPL-3.0-only
title: 'simstudy: Simulation of Study Data'
version: 0.7.1.9000
version: 0.8.0.9000
doi: 10.21105/joss.02763
identifiers:
- type: doi
value: 10.32614/CRAN.package.simstudy
- type: url
value: https://kgoldfeld.github.io/simstudy/dev/
abstract: Simulates data sets in order to explore modeling techniques or better understand
data generating processes. The user specifies a set of relationships between covariates,
and generates data based on these specifications. The final data sets can represent
Expand Down Expand Up @@ -49,7 +54,7 @@ preferred-citation:
repository: https://CRAN.R-project.org/package=simstudy
repository-code: https://github.com/kgoldfeld/simstudy
url: https://kgoldfeld.github.io/simstudy/
date-released: '2024-05-10'
date-released: '2024-07-19'
contact:
- family-names: Goldfeld
given-names: Keith
Expand Down Expand Up @@ -97,6 +102,7 @@ references:
given-names: Toby
orcid: https://orcid.org/0000-0002-3146-0865
year: '2024'
doi: 10.32614/CRAN.package.data.table
- type: software
title: glue
abstract: 'glue: Interpreted String Literals'
Expand All @@ -112,6 +118,7 @@ references:
email: jenny@posit.co
orcid: https://orcid.org/0000-0002-6983-2759
year: '2024'
doi: 10.32614/CRAN.package.glue
- type: software
title: methods
abstract: 'R: A Language and Environment for Statistical Computing'
Expand All @@ -122,6 +129,7 @@ references:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: '2024'
doi: 10.32614/CRAN.package.methods
- type: software
title: mvnfast
abstract: 'mvnfast: Fast Multivariate Normal and Student''s t Methods'
Expand All @@ -133,6 +141,7 @@ references:
given-names: Matteo
email: matteo.fasiolo@gmail.com
year: '2024'
doi: 10.32614/CRAN.package.mvnfast
- type: software
title: Rcpp
abstract: 'Rcpp: Seamless R and C++ Integration'
Expand All @@ -159,6 +168,7 @@ references:
- family-names: Chambers
given-names: John
year: '2024'
doi: 10.32614/CRAN.package.Rcpp
- type: software
title: backports
abstract: 'backports: Reimplementations of Functions Introduced Since R-3.0.0'
Expand All @@ -170,8 +180,12 @@ references:
given-names: Michel
email: michellang@gmail.com
orcid: https://orcid.org/0000-0001-9754-0393
- family-names: Murdoch
given-names: Duncan
email: murdoch.duncan@gmail.com
- name: R Core Team
year: '2024'
doi: 10.32614/CRAN.package.backports
- type: software
title: fastglm
abstract: 'fastglm: Fast and Stable Fitting of Generalized Linear Models using ''RcppEigen'''
Expand All @@ -183,6 +197,7 @@ references:
given-names: Jared
email: jaredhuling@gmail.com
year: '2024'
doi: 10.32614/CRAN.package.fastglm
- type: software
title: covr
abstract: 'covr: Test Coverage for Packages'
Expand All @@ -194,6 +209,7 @@ references:
given-names: Jim
email: james.f.hester@gmail.com
year: '2024'
doi: 10.32614/CRAN.package.covr
- type: software
title: dplyr
abstract: 'dplyr: A Grammar of Data Manipulation'
Expand All @@ -218,6 +234,7 @@ references:
email: davis@posit.co
orcid: https://orcid.org/0000-0003-4777-038X
year: '2024'
doi: 10.32614/CRAN.package.dplyr
- type: software
title: formatR
abstract: 'formatR: Format R Code Automatically'
Expand All @@ -230,6 +247,7 @@ references:
email: xie@yihui.name
orcid: https://orcid.org/0000-0003-0645-5666
year: '2024'
doi: 10.32614/CRAN.package.formatR
- type: software
title: gee
abstract: 'gee: Generalized Estimation Equation Solver'
Expand All @@ -239,6 +257,7 @@ references:
- family-names: Carey
given-names: Vincent J
year: '2024'
doi: 10.32614/CRAN.package.gee
- type: software
title: ggplot2
abstract: 'ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics'
Expand Down Expand Up @@ -278,6 +297,7 @@ references:
name-particle: van den
orcid: https://orcid.org/0000-0002-9335-7468
year: '2024'
doi: 10.32614/CRAN.package.ggplot2
- type: software
title: grid
abstract: 'R: A Language and Environment for Statistical Computing'
Expand All @@ -288,6 +308,7 @@ references:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: '2024'
doi: 10.32614/CRAN.package.grid
- type: software
title: gridExtra
abstract: 'gridExtra: Miscellaneous Functions for "Grid" Graphics'
Expand All @@ -298,6 +319,7 @@ references:
given-names: Baptiste
email: baptiste.auguie@gmail.com
year: '2024'
doi: 10.32614/CRAN.package.gridExtra
- type: software
title: hedgehog
abstract: 'hedgehog: Property-Based Testing'
Expand All @@ -309,6 +331,7 @@ references:
given-names: Huw
email: huw.campbell@gmail.com
year: '2024'
doi: 10.32614/CRAN.package.hedgehog
- type: software
title: knitr
abstract: 'knitr: A General-Purpose Package for Dynamic Report Generation in R'
Expand All @@ -321,6 +344,7 @@ references:
email: xie@yihui.name
orcid: https://orcid.org/0000-0003-0645-5666
year: '2024'
doi: 10.32614/CRAN.package.knitr
- type: software
title: magrittr
abstract: 'magrittr: A Forward-Pipe Operator for R'
Expand All @@ -335,6 +359,7 @@ references:
given-names: Hadley
email: hadley@rstudio.com
year: '2024'
doi: 10.32614/CRAN.package.magrittr
- type: software
title: Matrix
abstract: 'Matrix: Sparse and Dense Matrix Classes and Methods'
Expand All @@ -353,6 +378,7 @@ references:
given-names: Mikael
orcid: https://orcid.org/0000-0002-3542-2938
year: '2024'
doi: 10.32614/CRAN.package.Matrix
- type: software
title: mgcv
abstract: 'mgcv: Mixed GAM Computation Vehicle with Automatic Smoothness Estimation'
Expand All @@ -363,6 +389,7 @@ references:
given-names: Simon
email: simon.wood@r-project.org
year: '2024'
doi: 10.32614/CRAN.package.mgcv
- type: software
title: ordinal
abstract: 'ordinal: Regression Models for Ordinal Data'
Expand All @@ -374,6 +401,7 @@ references:
given-names: Rune Haubo Bojesen
email: rune.haubo@gmail.com
year: '2024'
doi: 10.32614/CRAN.package.ordinal
- type: software
title: pracma
abstract: 'pracma: Practical Numerical Math Functions'
Expand All @@ -384,6 +412,7 @@ references:
given-names: Hans W.
email: hwborchers@googlemail.com
year: '2024'
doi: 10.32614/CRAN.package.pracma
- type: software
title: rmarkdown
abstract: 'rmarkdown: Dynamic Documents for R'
Expand Down Expand Up @@ -427,6 +456,7 @@ references:
email: rich@posit.co
orcid: https://orcid.org/0000-0003-3925-190X
year: '2024'
doi: 10.32614/CRAN.package.rmarkdown
- type: software
title: scales
abstract: 'scales: Scale Functions for Visualization'
Expand All @@ -444,6 +474,7 @@ references:
- family-names: Seidel
given-names: Dana
year: '2024'
doi: 10.32614/CRAN.package.scales
- type: software
title: splines
abstract: 'R: A Language and Environment for Statistical Computing'
Expand All @@ -454,6 +485,7 @@ references:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: '2024'
doi: 10.32614/CRAN.package.splines
- type: software
title: survival
abstract: 'survival: Survival Analysis'
Expand All @@ -465,6 +497,7 @@ references:
given-names: Terry M
email: therneau.terry@mayo.edu
year: '2024'
doi: 10.32614/CRAN.package.survival
- type: software
title: testthat
abstract: 'testthat: Unit Testing for R'
Expand All @@ -476,6 +509,7 @@ references:
given-names: Hadley
email: hadley@posit.co
year: '2024'
doi: 10.32614/CRAN.package.testthat
- type: software
title: gtsummary
abstract: 'gtsummary: Presentation-Ready Data Summary and Analytic Result Tables'
Expand Down Expand Up @@ -503,6 +537,24 @@ references:
given-names: Emily C.
orcid: https://orcid.org/0000-0002-1402-4498
year: '2024'
doi: 10.32614/CRAN.package.gtsummary
- type: software
title: broom.helpers
abstract: 'broom.helpers: Helpers for Model Coefficients Tibbles'
notes: Suggests
url: https://larmarange.github.io/broom.helpers/
repository: https://CRAN.R-project.org/package=broom.helpers
authors:
- family-names: Larmarange
given-names: Joseph
email: joseph@larmarange.net
orcid: https://orcid.org/0000-0001-7097-700X
- family-names: Sjoberg
given-names: Daniel D.
email: danield.sjoberg@gmail.com
orcid: https://orcid.org/0000-0003-0862-2018
year: '2024'
doi: 10.32614/CRAN.package.broom.helpers
- type: software
title: survminer
abstract: 'survminer: Drawing Survival Curves using ''ggplot2'''
Expand All @@ -520,6 +572,7 @@ references:
given-names: Przemyslaw
email: przemyslaw.biecek@gmail.com
year: '2024'
doi: 10.32614/CRAN.package.survminer
- type: software
title: katex
abstract: 'katex: Rendering Math to HTML, ''MathML'', or R-Documentation Format'
Expand All @@ -532,6 +585,7 @@ references:
email: jeroen@berkeley.edu
orcid: https://orcid.org/0000-0002-4035-0289
year: '2024'
doi: 10.32614/CRAN.package.katex
- type: software
title: dirmult
abstract: 'dirmult: Estimation in Dirichlet-Multinomial Distribution'
Expand All @@ -542,6 +596,7 @@ references:
given-names: Torben
email: tvede@math.aau.dk
year: '2024'
doi: 10.32614/CRAN.package.dirmult
- type: software
title: rms
abstract: 'rms: Regression Modeling Strategies'
Expand All @@ -553,6 +608,7 @@ references:
given-names: Frank E
email: fh@fharrell.com
year: '2024'
doi: 10.32614/CRAN.package.rms
- type: software
title: pbv
abstract: 'pbv: Probabilities for Bivariate Normal Distribution'
Expand All @@ -564,8 +620,6 @@ references:
given-names: Alexander
orcid: https://orcid.org/0000-0002-8226-3132
year: '2024'
doi: 10.32614/CRAN.package.pbv
version: '>= 0.4-22'
identifiers:
- type: url
value: https://kgoldfeld.github.io/simstudy/dev/

3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: simstudy
Title: Simulation of Study Data
Version: 0.8.0.9000
Date: 2024-05-14
Date: 2024-07-19
Authors@R:
c(person(given = "Keith",
family = "Goldfeld",
Expand Down Expand Up @@ -57,6 +57,7 @@ Suggests:
survival,
testthat,
gtsummary,
broom.helpers,
survminer,
katex,
dirmult,
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

## Minor fix
* `addCorGen` no longer requires all clusters to have the same size when using the *rho* and *corstr* arguments to define the correlation.
* Fixed an issue that prevented functions defined outside the global namespace from being referenced in `defData`.

# simstudy 0.8.0

Expand Down
11 changes: 6 additions & 5 deletions R/generate_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ genSpline <- function(dt, newvar, predictor, theta,
#' @param keepEvents Indicator to retain original "events" columns. Defaults
#' to FALSE.
#' @param idName Name of id field in existing data set.
#' @param envir Optional environment, defaults to current calling environment.
#' @return Original data table with survival time
#' @examples
#' # Baseline data definitions
Expand Down Expand Up @@ -996,7 +997,7 @@ genSpline <- function(dt, newvar, predictor, theta,
#
genSurv <- function(dtName, survDefs, digits = 3,
timeName = NULL, censorName = NULL, eventName = "event",
typeName = "type", keepEvents = FALSE, idName = "id") {
typeName = "type", keepEvents = FALSE, idName = "id", envir = parent.frame()) {

# For double-dot notation

Expand Down Expand Up @@ -1042,13 +1043,13 @@ genSurv <- function(dtName, survDefs, digits = 3,
subDef <- survDefs[varname == events[i]]

formshape <- subDef[1, shape]
shape <- as.vector(.evalWith(formshape, .parseDotVars(formshape, envir = parent.frame()), dtSurv))
shape <- as.vector(.evalWith(formshape, .parseDotVars(formshape, envir = parent.frame()), dtSurv, envir = envir))

formscale <- subDef[1, scale]
scale <- as.vector(.evalWith(formscale, .parseDotVars(formscale, envir = parent.frame()), dtSurv))
scale <- as.vector(.evalWith(formscale, .parseDotVars(formscale, envir = parent.frame()), dtSurv, envir = envir))

formulas <- subDef[, formula]
form1 <- as.vector(.evalWith(formulas[1], .parseDotVars(formulas[1], envir = parent.frame()), dtSurv))
form1 <- as.vector(.evalWith(formulas[1], .parseDotVars(formulas[1], envir = parent.frame()), dtSurv, envir = envir))

if (nrow(subDef) > 1) {

Expand All @@ -1063,7 +1064,7 @@ genSurv <- function(dtName, survDefs, digits = 3,
transition <- subDef[2, transition]
t_adj <- transition ^ (1/shape)

form2 <- as.vector(.evalWith(formulas[2], .parseDotVars(formulas[2], envir = parent.frame()), dtSurv))
form2 <- as.vector(.evalWith(formulas[2], .parseDotVars(formulas[2], envir = parent.frame()), dtSurv, envir = envir))

threshold <- exp(form1) * t_adj
period <- 1*(nlogu < threshold) + 2*(nlogu >= threshold)
Expand Down
Loading

0 comments on commit 89e852a

Please sign in to comment.