The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
The rspdlite packages provides the tiny, fast, capable logger spdlite, implemented as a small C++20 header-only library, for use by R. It is related to its larger and more featureful cousing spdlog which we provide via RcppSpdlog – and the wrapping frontend spdl which polishes and unifies some user-interface aspects for the discerning R user and/or package developer.
tl does the same for
rspdlite: It
offers an entirely optional interface consistently using
namespaced calling convention for both R and C++. In other
words, one can added debugging informations such as
tl::info("Entering section foo") the same way in both R and
C++ (with an added semicolon, or course, and by adding a header for
declarations).
We can revisit the examples from the rspdlite package:
We can use the same C++ example from the spdlite docs, but now
accessing via the tl namespace:
tl::critical("-- level to warn");
tl::set_level("warn");
tl::error("Some error message with arg: {}", 1);
tl::warn("Easy padding in numbers like {:08d}", 12);
tl::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
tl::info("Support for floats {:03.2f}", 1.23456);
tl::info("Positional args are {1} {0}..", "too", "supported");
tl::info("{:<30}", "left aligned");The default logging level is ‘info’ so all these message would appear by default but as we alter the logging level dynamically to ‘warn’ fewer messages appear.
Following the nice user experience offered by spdl, we similarly provide access via the ‘package name colon colon’ patter from R:
tl::critical("-- level to debug")
tl::set_level("debug")
tl::info("Some more at info")
tl::error("Some error message with arg: {}", 1)
tl::error("Some error message with more args: {} and {}", 1, "abc")
tl::log_critical("-- level to error and calling example1 and example2")
tl::set_level("error")As for its cousin R packages, the format string here ‘resembles’ the full C++ format string, but remains simpler. As we convert each argument directly to a character (then passed on to the C++ layer) we do not offer the extra formatting options available directly from C++. We have not found this to be an issue.
tlexampleThe package tlexample offers a
complete example of integrated logging from both C++ and R. After
installing rspdlite and tl (along with their one
dependency Rcpp) one can run the
provided demo. So for example in an r2u container (such as
rocker/r2u where we rely on the GitHub installation helper
also pulling in dependencies Rcpp and
rspdlite as
binaries)
root$ installGithub.r eddelbuettel/tl eddelbuettel/tlexample
root$ Rscript -e 'demo(ex, package="tlexample")'or alternatively install Rcpp and these package from source or as binary from my r-universe. This tlexample package is very lightweight and therefore a good playground to experiment with logging via tl, rspdlite and spdlite.
Dirk Eddelbuettel
tl is released under the GNU GPL, version 2 or later, just like R itself.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.