Econometrics and Free Software by Bruno Rodrigues.
RSS feed for blog post updates.
Follow me on Mastodon, twitter, or check out my Github.
Check out my package that adds logging to R functions, {chronicler}.
Or read my free ebook to learn some R, Modern R with the tidyverse,
and if you're interested in setting up reproducible analytical pipelines,
read my other ebook.
You can also watch my youtube channel.
Buy me a coffee, my kids don't let me sleep.

chronicler is now available on CRAN

R

I am very happy to annouce that the {chronicler} package, which I’ve been working on for the past 3 months has been released on CRAN. Install it with:

install.packages("chronicler")

{chronicler} allows you to create objects that carry a log with them. Here is an example of an object that has been created using {chronicler}, and saved using saveRDS() (which we now load back into our session using readRDS()):

library(chronicler)

my_df <- readRDS("path/to/my_df.rds")

Printing my_df shows the following output:

my_df
## OK! Value computed successfully:
## ---------------
## Just
## # A tibble: 9 × 3
## # Groups:   species [9]
##   species    sex              mass
##   <chr>      <chr>           <dbl>
## 1 Clawdite   female           55  
## 2 Droid      none             69.8
## 3 Human      female           56.3
## 4 Hutt       hermaphroditic 1358  
## 5 Kaminoan   female          NaN  
## 6 Mirialan   female           53.1
## 7 Tholothian female           50  
## 8 Togruta    female           57  
## 9 Twi'lek    female           55  
## 
## ---------------
## This is an object of type `chronicle`.
## Retrieve the value of this object with pick(.c, "value").
## To read the log of this object, call read_log(.c).

my_df is made up of two parts, one is a data set, and the other is the log. If you wish to know how this data set was created, you can call read_log(my_df) (this function will be renamed to read.log() in the next release, to avoid clashing with readr::read_log()):

read_log(my_df)
## [1] "Complete log:"                                                                  
## [2] "OK! select(height,mass,species,sex) ran successfully at 2022-05-18 10:56:52"    
## [3] "OK! group_by(species,sex) ran successfully at 2022-05-18 10:56:52"              
## [4] "OK! filter(sex != \"male\") ran successfully at 2022-05-18 10:56:52"            
## [5] "OK! summarise(mean(mass, na.rm = TRUE)) ran successfully at 2022-05-18 10:56:52"
## [6] "Total running time: 0.185953617095947 secs"

if you want to get the dataset out of the {chronicler} “box”, you can do so with pick(my_df, "value"):

pick(my_df, "value")
## # A tibble: 9 × 3
## # Groups:   species [9]
##   species    sex              mass
##   <chr>      <chr>           <dbl>
## 1 Clawdite   female           55  
## 2 Droid      none             69.8
## 3 Human      female           56.3
## 4 Hutt       hermaphroditic 1358  
## 5 Kaminoan   female          NaN  
## 6 Mirialan   female           53.1
## 7 Tholothian female           50  
## 8 Togruta    female           57  
## 9 Twi'lek    female           55

To know more about all the package has to offer, read the readme and the vignettes on the package’s website. I’m already working on the next release, where I plan to add the following features:

  • Rename read_log() to read.log()
  • Make {chronicler} work with {ggplot2} (as described here)
  • Introduce functions to save {chronicler} objects as .csv or .xlsx files to disk (if the underlying value is a data.frame, as in the example above)
  • Anything else I think of between now and then!

I’m really looking forward to see how people are going to use this package for their work, personally I’ve been mixing {chronicler} with {targets} to build very robust pipelines to build chronicle objects!

Thanks

I’d like to thank armcn, Kupac for their blog posts (here) and packages (maybe) which inspired me to build this package. Thank you as well to TimTeaFan for his help with writing the %>=% infix operator, nigrahamuk for showing me a nice way to catch errors, and finally Mwavu for pointing me towards the right direction with an issue I’ve had as I started working on this package. Thanks to Putosaure for designing the hex logo, and of course to every single person that makes free and open source software possible.

Hope you enjoyed! If you found this blog post useful, you might want to follow me on twitter for blog post updates and buy me an espresso or paypal.me, or buy my ebook on Leanpub. You can also watch my videos on youtube. So much content for you to consoom!

Buy me an EspressoBuy me an Espresso