clonecensorweighting is an R package for building reproducible
clone-censor-weighting workflows for target trial emulation.
This repository is meant to be easy to use from a fresh GitHub clone and easy to maintain as a shared collaboration project. The recommended setup uses:
rigto install and switch to the project R versionrenvto restore the same package environment for every collaborator- GitHub Actions to check reproducibility and package health
git clone https://github.com/CausalInferenceLab/clonecensorweighting.git
cd clonecensorweightingThis project is pinned to R 4.4.2 for reproducibility.
rig add 4.4.2
rig default 4.4.2If you already have R 4.4.2, you can skip rig add 4.4.2.
Open R in the project directory and run:
install.packages("renv")
renv::restore()renv::restore() installs the package versions recorded in renv.lock, so
everyone works with the same dependency set.
Note: this repository includes a .Rprofile file that activates renv
automatically when you open the project in R.
From the project root:
R CMD INSTALL .Then in R:
library(clonecensorweighting)library(clonecensorweighting)
trial_data <- tibble::tibble(
id = c(1, 2),
follow_up = c(10, 12),
event = c(1, 0),
treatment = c("A", "B")
)
clones <- clone_censor_weighting(
data = trial_data,
id = "id",
follow_up = "follow_up",
event = "event",
treatment = "treatment",
regimes = c("A", "B")
)
clones
make_surv_response(
data = trial_data,
follow_up = "follow_up",
event = "event"
)The package is still an early, lightweight foundation for future work. Right now it includes:
read_trial_data()to read trial-style CSV data into a tibbleclone_censor_weighting()to create a starter cloned dataset across regimesmake_surv_response()to build asurvival::Surv()response object
For collaborative work, the safest pattern is:
- Clone the repository.
- Switch to R
4.4.2withrig. - Run
renv::restore(). - Make your changes in a branch.
- Run checks before opening a pull request.
Useful commands:
R CMD INSTALL .
R CMD check --no-manual .In R:
testthat::test_local()If you add, remove, or upgrade dependencies, update the lockfile from R:
renv::settings$snapshot.type("explicit")
renv::status(dev = TRUE)
renv::snapshot(dev = TRUE)Please commit both code changes and the updated renv.lock when dependency
changes are intentional.
This repository includes two GitHub Actions workflows:
check-reproducible.yamlrunsR CMD checkwith pinned R4.4.2andrenvcheck-latest.yamlruns broader checks across operating systems and R versions
Together, these workflows help keep the project reproducible for collaborators and stable for future users.