epiverse-trace / finalsize

R package to calculate the final size of an SIR epidemic in populations with heterogeneity in social contacts and disease susceptibility
https://epiverse-trace.github.io/finalsize/
Other
11 stars 7 forks source link

Change how to load external packages in vignettes #123

Closed avallecam closed 1 year ago

avallecam commented 1 year ago

I have three alternatives for this chunk: https://github.com/epiverse-trace/finalsize/blob/f0ac4127e54579754d08ee92754203f99c0f6ee9/vignettes/finalsize.Rmd#L61-L67


(1) This alternative propose to use pacman to simplify two steps:

library(finalsize)

# load necessary packages
if(!require("pacman")) install.packages("pacman")
pacman::p_load(socialmixer, data.table, ggplot2)

An argument for not using pacman here is that it may be more useful for reproducible workflows than for package documentation. But showing it here could also highlight our preference for it in user projects.


(2) This one avoids evaluating the availability and installation of external packages. But propose to remove library(data.table) because, similar to socialmixer, it is used for one function of secondary relevance, with respect to finalsize and ggplot2:

library(finalsize)

# load necessary packages
library(ggplot2)

This modification requires to call data.table with the double-colon notation data.table::merge.data.table() here: https://github.com/epiverse-trace/finalsize/blob/f0ac4127e54579754d08ee92754203f99c0f6ee9/vignettes/finalsize.Rmd#L236


(3) This last one avoids using pacman but uses longer code to evaluate the availability and installation of packages. Also, it is consistent with #117 :

library(finalsize)

# load necessary packages
if(!require("socialmixer")) install.packages("socialmixer")
if(!require("data.table")) install.packages("data.table")
if(!require("ggplot2")) install.packages("ggplot2")
library(ggplot2)

This one also requires to call data.table with the double-colon notation data.table::merge.data.table() here: https://github.com/epiverse-trace/finalsize/blob/f0ac4127e54579754d08ee92754203f99c0f6ee9/vignettes/finalsize.Rmd#L236

pratikunterwegs commented 1 year ago

I think option (2) is best here as it doesn't require pacman. I've removed data.table and preferred base R funs to work with data frame.

avallecam commented 1 year ago

I agree! Additionally, this can be also applied in the other vignettes:

pratikunterwegs commented 1 year ago

I think you might be referring to an older version of these files - I don't use {data.table} at all now, and data.table::rbindlist has been replaced with Reduce(f = rbind, ...)

avallecam commented 1 year ago

Right, thanks for the clarification!