MyNixOS website logo
Description

Easier Use of 'RcppSpdlog' Functions via Wrapper.

Logging functions in 'RcppSpdlog' provide access to the logging functionality from the 'spdlog' 'C++' library. This package offers shorter convenience wrappers for the 'R' functions which match the 'C++' functions, namely via, say, 'spdl::debug()' at the debug level. The actual formatting is done by the 'fmt::format()' function from the 'fmtlib' library (that is also 'std::format()' in 'C++20' or later).

spdl: A consistent C++ and R interface to spdlog

CI CRAN Dependencies Downloads License Last Commit

About

The RcppSpdlog repository (and CRAN package) provides access to the wonderful spdlog library along with the fmt library.

This permits use in C++ extensions for R by offering the spdlog (header-only) library along with the (header-only) fmt library (by using LinkingTo as described in Section 1.1.3 of WRE). More recently, RcppSpdlog was extended so that it provides a set of key functions directly for use by other R functions (as described in Section 5.4.3 of WRE).

However, now the use of, say, a debug logging message from C++ looks like

// in C++
spdlog::debug("Text with {} text {} which is {}", "auto", "expansion", 42);

whereas in R, given the RcppSpdlog package and namespace, it looks like this (if we use sprintf() to assemble the message)

# in R
RcppSpdlog::log_debug(sprintf("Text with %s text %s which is %s", "auto", "expansion", 42L)

and that irked us. Enter this package! By owning the spld namespace (in R) and an easily overlayed namespace in C++ of the same name we can do

// in C++
spdl::debug("Text with {} text {} which is {}", "auto", "expansion", 42);

as well as (still using sprintf())

# in R
spdl::debug(sprintf("Text with %s text %s which is %s", "auto", "expansion", 42L))

which is much better as it avoids context switching. Better still, with the internal formatter we can write the same format string as in C++ and not worry about format details:

# in R
spdl::debug("Text with {} text {} which is {}", "auto", "expansion", 42L)

Details

We use a simple mechanism in which all R arguments are passed through format() by default to render strings, and then pass a single vector of strings argument through the restrictive C language Foreign Function Interface to RcppSpdlog where it can be passed to the C++ layer available there.

This also means we use the fmt library in both languages as the formatter. We prefer this is over other string-interpolating libraries in R which are similar but subtly different. Should their use be desired, they can of course be used: the default call to any of the loggers is just a single-argument call with a text variable so users are free to expand strings as they please. Anything starting from paste and sprintf works.

As of release 0.0.2, we also expose helpers spdl::fmt() (to format) and spdl::cat() (to display).

Namespace

Note that because the package uses functions names also present in the base R packages (namely cat, debug, drop, trace) we do not recommend loading the package. Instead, call it with the explicit prefix as e.g.spdl::debug("Some message {}", foo). As a selective importFrom one can always do importFrom("spdl", "setup") combined with the explicit pre-fix use.

Author

Dirk Eddelbuettel

License

spdl is released under the GNU GPL, version 2 or later, just like R itself.

Metadata

Version

0.0.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows