needed_packages <- c(
"data.table", "broom", "purrr", "dagitty", "ggplot2", "dplyr", "marginaleffects",
"MatchIt","survey","tableone"
)
cran_repo <- "https://mirror.lyrahosting.com/CRAN/" # <- a CRAN mirror in the Netherlands, can select another one from here https://cran.r-project.org/mirrors.html
available_pkgs <- available.packages(repos = cran_repo)
for (pkg in needed_packages) {
if (!pkg %in% rownames(available_pkgs)) {
warning(sprintf("Package %s is not available from the configured CRAN repo.", sQuote(pkg)))
next
}
installed_version <- tryCatch(
as.character(packageVersion(pkg)),
error = function(e) NA_character_
)
cran_version <- available_pkgs[pkg, "Version"]
if (is.na(installed_version) || compareVersion(installed_version, cran_version) < 0) {
install.packages(pkg, repos = cran_repo)
}
}We will work with R. You can use your preferred way of working in R to do the practicals. Our preferred way is this:
- Create a new folder with a good name, e.g.,
practicals_causal_datascience - Open RStudio
- Create a new project from RStudio, which you associate with the folder
- Create a
raw_datasubfolder - Create an R script for the current practical, e.g.,
introduction.R - Create your well-documented and well-styled code in this R script
We try to make our practicals light in the number of required packages, but the packages below are needed. You can install them via: