loggr
: Bringing the pipe to logging since 2016loggr
tries to make logging in R easier. It lets you mix logging statements naturally with the %>%
operator from magrittr.
It also comes with some nice features -- flags, verbosity settings, redirecting logs to a file -- that come in handy when deploying R in production.
The easiest install is with with devtools
library(devtools)
install_github("erickramer/loggr")
loggr
comes with some useful features. Check out these examples.
Mix logging statements with your code. loggr
always returns its first argument, which makes it easy to use with the pipe.
iris_filtered = iris %>%
loggr("I'm a fan of logging") %>%
filter(Species == "setosa") %>%
loggr("Like a really big fan")
Access the first argument of the function with .
iris_filtered = iris %>%
loggr("I see you have", nrow(.), "rows") %>%
filter(Species == "setosa") %>%
loggr("And now you have", nrow(.), "rows")
Add flags to your logs.
iris_filtered = iris %>%
loggr("Look at these logs!", .flags=c("flag1", "flag2")) %>%
filter(Species == "setosa")
Or set flags globally
loggr_flags("foo", "bar")
Use loggr_level
to set the vebosity level for your logs (ascending is less verbose). You can keep your script the same and just change one parameter to set how many logging statements you see.
loggr_level(5)
iris_filtered = iris %>%
loggr("This message isn't so important", .level=1) %>%
filter(Species == "setosa") %>%
loggr("But this one is", .level=10)
open_log("mylog.txt")
iris_filtered = iris %>%
loggr("This is going to a file!") %>%
filter(Species == "setosa")
close_log()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.