Blog

R-Package Advent Calendar 2020

Dec 25, 2020 | 3 minutes read

Categories:

Tags: R, Advent calendar, Packages

This year has been truly something different for us all. Blogging has definitely taken a toll, as real life has been quite something to handle. So, in order to end the year with a bang, and something fun, I started a twitter advent calendar!

The advent calendar is one R-package per day that I personally use and find very useful in my work. The hope is that it would give people a mix of familiar and less familiar packages that might help their work too. In each package sub-thread, I try to highlight some functions or functionality from the various packages that I like in particular. There are so many packages on CRAN and other online repositories (BioConductor, GitHub, Gitlab, NeuroConductor etc.), that it can be hard to find something to help you along. I hope this atleast points you in a good direction. There are other packages that could cover some or all of the same functionality as the ones listed here, but these are the ones I personally use.

Before I started the calendar (one day late!), I sat down and wrote a list of all the packages I wanted in my advent calendar.

The rules were:

  • One package per day
  • I must personally use it
  • I can find easy examples of why I like using it

The point of the calendar was to do something fun, that others might find useful, and that would highlight and give credit to great packages. But I also did not have the possibility of spending lots of time researching other alternative options or the like, it was to be a light-weight and easy thing for me to do.

So i wrote down my list in R:

pks <- c("usethis", "rio", "distill", 
         "boom", "patchwork", "holepunch",
         "learnr", "xaringan", "magick",
         "nettskjemar", "pkgdown", "here",
         "rticles", "vitae", "xaringanExtra",
         "stringr", "forcats", "lubridate", 
         "glue", "janitor", "pbmcapply",
         "kableExtra", "papayar", "reactable")

Then I made a little function that would draw a random one every time I ran it, while omitting the ones I had drawn before

get_todays <- function(completed, pkgs){
  days <- 1:24
  days <- days[!days %in% completed]
  k <- sample(days, 1)  
  cat(pkgs[k], "\n")
  k
}

Now I had an itty bitty function that would draw from my list by random each day, so I did not have to think about the order of things. Every day I drew a new package, tweeted about it, and added it to the completed list.

completed <- c(3, 12, 19, 6, 8, 1, 
               10, 16, 22, 5, 
               17, 21, 18, 9, 7)

get_todays(completed, pks)
## xaringanExtra
## [1] 15

Now, there is a slight problem with my function. I forgot to add a random seed, as pointed out by Tobias Busch

So, always room for improvement! If I do something similar next year, I’ll be sure to add that!

Have a great Christmas, everyone!

Citation

For attribution, please cite this work as

Dr. Mowinckel (Dec 25, 2020) R-Package Advent Calendar 2020. Retrieved from https://drmowinckels.io/blog/r-package-advent-calendar-2020/

BibTeX citation

@misc{ 2020-r-package-advent-calendar-2020,
 author = { Dr. Mowinckel },
 title = { R-Package Advent Calendar 2020 },
 url = { https://drmowinckels.io/blog/r-package-advent-calendar-2020/ },
 year = { 2020 }
 updated = { Oct 19, 2023 }
}