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

use local environment for fitdist call #113

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ Authors@R:
family = "Howes",
role = c("ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-2386-4031")))
comment = c(ORCID = "0000-0003-2386-4031")),
person(given = "Sebastian",
family = "Funk",
role = c("ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-2842-3406")))
Description: This package provides both R functions for working with primary
event censored distributions and Stan implementations for use in Bayesian
modeling. Primary event censored distributions are useful for modeling
Expand All @@ -40,7 +45,8 @@ Suggests:
rmarkdown,
spelling,
testthat (>= 3.1.9),
usethis
usethis,
withr
Additional_repositories:
https://stan-dev.r-universe.dev
Config/Needs/hexsticker: hexSticker, sysfonts, ggplot2
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is the development version of `primarycensoreddist` and is not yet ready fo
## Package

* Split "Why it works" vignette into two separate vignettes, "Why it works" and "Analytic solutions for censored delay distributions".
* Removed the need to assign functions to the global environment for `fitdistdoublecens()` by using `withr`.

# primarycensoreddist 0.5.0

Expand Down
10 changes: 3 additions & 7 deletions R/fitdistdoublecens.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,12 @@ fitdistdoublecens <- function(censdata, distr,
}
formals(ppcens_dist) <- formals(pdist)

assign("d.pcens_dist", dpcens_dist, envir = .GlobalEnv)
assign("p.pcens_dist", ppcens_dist, envir = .GlobalEnv)

# Fit the distribution
fit <- fitdistrplus::fitdist(
fit <- withr::with_environment(environment(), fitdistrplus::fitdist(
censdata$left,
distr = ".pcens_dist",
distr = "pcens_dist",
...
)
rm(dpcens_dist, ppcens_dist)
))
return(fit)
}

Expand Down
Loading