A 'C++20' API for R
Overview
A header-only 'C++20' API for manipulating R data structures from 'C++'. Provides 'C++20' concepts specific to R, custom scalar and vector classes with built-in NA handling, automatic object protection, 'SIMD' (single-instruction-multiple-data), parallelisation, and a streamlined system for registering 'C++' functions, including templates, to R. Full API reference and documentation are available at https://nicchr.github.io/cppally/.
Breaking changes
- Improved type-safety regarding implicit coercion of RScalar types. They now
can implicitly coerce **only** to their wrapped types, whereas before they
could implicitly coerce to that as well as other C types.
RTimeTypearithmetic has been deprecated and removed.- Arithmetic involving
r_lglis now always promoted tor_int, matching R's
own semantics.
common_math_t<T, U>now never returnsr_lgl, effectively treatingr_lgl
as r_int.
Bug fixes
- Fixed bug where exclusion of concepts header was affecting vignette creation on macos.
- Fixed incorrect NA handling of
r_dateandr_psxct.
Show all changes in 1.1.0Hide the rest of the changes in 1.1.0
- Fixed a bug where
identical()would returnfalsefor two genuinely
identical NA_real_ values.
NULLoptional arguments are now correctly handled.
Vector, factor and data frame arguments can now be NULL to allow for optional
argument programming from R.
- Fixed a bug where checking exact equality (via
identical) for C/C++ types
was not compiling due to template ordering issue.
r_lgl (logical) semantics
r_lglcan now implicitly coerce toint(and onlyint), consistent with
the other RScalar types.
r_lglvalues are now always normalised on construction internally to either
0, 1, or NA.
Arithmetic
- Integer overflow is now explicitly handled in all cppally arithmetic, returning
NA when detected. Integer addition and subtraction in particular are
written using branchless or vectorisable code, enabling SIMD vectorisation.
- Integer in-place division
/=now matches R's%/%
(floored division), instead of C's truncating division, e.g. -7L /= 2L now
gives -4 instead of -3. Division by zero or NA now correctly returns
NA instead of crashing the R session. Precision is also preserved for large
r_int64 values that previously round-tripped through double.
- Scalar in-place arithmetic that narrows a wider result back to the left-hand
type (e.g. r_int += r_int64) now checks the value fits first,
giving NA on overflow instead of a silently wrapped result.
%now accepts mixed integer/float operands (e.g.r_int(7) % 2.5),
promoting and flooring consistent with R's %%.
- Vector in-place arithmetic (
+=,-=,*=,%=) now routes through the
scalar operators, fixing a bug where mixed-width operations (e.g.
r_vec<r_int> += r_vec<r_int64>) could silently truncate values, including
turning NA into 0.
Improvements
- Better errors when passing invalid types to template functions.
- Constructing invalid dates and date-times now returns
NAinstead of
an error.
- New concept
RNumberto represent number-based types liker_intandr_dbl. - New member
is_nafor RScalar types, in addition to the equivalent
is_na free function.
- New member function
na()for RScalar classes. - Relational operators have been extended to cover all RNumericType classes
which includes r_date and r_psxct.
From NEWS.md in the release
Install
Health
ERRORre-building of vignette outputsr-oldrel-macos-arm64, r-oldrel-macos-x86_64, r-release-macos-x86_64
r-oldrel-macos-arm64
Error(s) in re-building vignettes:
--- re-building ‘cppally.Rmd’ using rmarkdown
Quitting from cppally.Rmd:85-467 [unnamed-chunk-5]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error:
! Compilation failed:
using C++ compiler: ‘Apple clang version 14.0.3 (clang-1403.0.22.14.1)’
using C++20
using SDK: ‘MacOSX11.3.1.sdk’
In file included from /Volumes/Temp/tmp/RtmpdHyCPu/fileca4910c8f907/src/cppally.cpp:1:
In file included from /Volumes/Builds/packages/big-sur-arm64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_dispatch.h:13:
In file included from /Volumes/Builds/packages/big-sur-arm64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_sexp_types.h:8:
/Volumes/Builds/packages/big-sur-arm64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_concepts.h:292:25: error: no member named 'cmp_less_equal' in namespace 'std'
return std::cmp_less_equal(
~~~~~^
/Volumes/Builds/packages/big-sur-arm64/re
...[truncated]...
heck/cppally/include/cppally/r_types.h:6:
In file included from /Volumes/Builds/packages/big-sur-arm64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_lgl.h:7:
/Volumes/Builds/packages/big-sur-arm64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_int.h:15:15: error: substitution into constraint expression resulted in a non-constant expression
requires (internal::lossless_numeric_cast<T, int>())
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Volumes/Builds/packages/big-sur-arm64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_lgl.h:20:52: note: while checking constraint satisfaction for template 'r_int<int>' required here
explicit constexpr r_lgl(int x) noexcept : value(r_int(x).is_na() ? x : static_cast<int>(static_cast<bool>(x)
--- failed re-building ‘vector_name_hashing.Rmd’
SUMMARY: processing the following files failed:
‘cppally.Rmd’ ‘functionals.Rmd’ ‘protection.Rmd’
‘vector_name_hashing.Rmd’
Error: Vignette re-building failed.
Execution haltedr-oldrel-macos-x86_64
Error(s) in re-building vignettes:
--- re-building ‘cppally.Rmd’ using rmarkdown
Quitting from cppally.Rmd:85-467 [unnamed-chunk-5]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error:
! Compilation failed:
using C++ compiler: ‘Apple clang version 14.0.3 (clang-1403.0.22.14.1)’
using C++20
using SDK: ‘MacOSX11.3.1.sdk’
In file included from /Volumes/Temp/tmp/Rtmpv2urhj/fileb53c248346f2/src/cppally.cpp:1:
In file included from /Volumes/Builds/packages/big-sur-x86_64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_dispatch.h:13:
In file included from /Volumes/Builds/packages/big-sur-x86_64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_sexp_types.h:8:
/Volumes/Builds/packages/big-sur-x86_64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_concepts.h:292:25: error: no member named 'cmp_less_equal' in namespace 'std'
return std::cmp_less_equal(
~~~~~^
/Volumes/Builds/packages/big-sur-x86_6
...[truncated]...
sur-x86_64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_types.h:6:
In file included from /Volumes/Builds/packages/big-sur-x86_64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_lgl.h:7:
/Volumes/Builds/packages/big-sur-x86_64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_int.h:15:15: error: substitution into constraint expression resulted in a non-constant expression
requires (internal::lossless_numeric_cast<T, int>())
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Volumes/Builds/packages/big-sur-x86_64/results/4.5/cppally.Rcheck/cppally/include/cppally/r_lgl.h:20:52: note: while checking constraint satisfaction for template 'r_int<int>' required here
explicit constexpr r_lgl(int x) noexcept : value(r_int(x).is_na() ? x : s
--- failed re-building ‘vector_name_hashing.Rmd’
SUMMARY: processing the following files failed:
‘cppally.Rmd’ ‘functionals.Rmd’ ‘protection.Rmd’
‘vector_name_hashing.Rmd’
Error: Vignette re-building failed.
Execution haltedr-release-macos-x86_64
Error(s) in re-building vignettes:
--- re-building ‘cppally.Rmd’ using rmarkdown
Quitting from cppally.Rmd:85-467 [unnamed-chunk-5]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error:
! Compilation failed:
specified C++20
using C++ compiler: ‘Apple clang version 14.0.3 (clang-1403.0.22.14.1)’
using C++20
using SDK: ‘MacOSX11.3.1.sdk’
In file included from /Volumes/Temp/tmp/RtmpeIzaBU/file14e90705c29bc/src/cppally.cpp:1:
In file included from /Volumes/Builds/packages/big-sur-x86_64/results/4.6/cppally.Rcheck/cppally/include/cppally/r_dispatch.h:13:
In file included from /Volumes/Builds/packages/big-sur-x86_64/results/4.6/cppally.Rcheck/cppally/include/cppally/r_sexp_types.h:8:
/Volumes/Builds/packages/big-sur-x86_64/results/4.6/cppally.Rcheck/cppally/include/cppally/r_concepts.h:292:25: error: no member named 'cmp_less_equal' in namespace 'std'
return std::cmp_less_equal(
~~~~~^
/Volumes/Builds/packa
...[truncated]...
Builds/packages/big-sur-x86_64/results/4.6/cppally.Rcheck/cppally/include/cppally/r_types.h:6:
In file included from /Volumes/Builds/packages/big-sur-x86_64/results/4.6/cppally.Rcheck/cppally/include/cppally/r_lgl.h:7:
/Volumes/Builds/packages/big-sur-x86_64/results/4.6/cppally.Rcheck/cppally/include/cppally/r_int.h:15:15: error: substitution into constraint expression resulted in a non-constant expression
requires (internal::lossless_numeric_cast<T, int>())
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Volumes/Builds/packages/big-sur-x86_64/results/4.6/cppally.Rcheck/cppally/include/cppally/r_lgl.h:20:52: note: while checking constraint satisfaction for template 'r_int<int>' required here
explicit constexpr r_lgl(int x) noexcept : value(r_in
--- failed re-building ‘vector_name_hashing.Rmd’
SUMMARY: processing the following files failed:
‘cppally.Rmd’ ‘functionals.Rmd’ ‘protection.Rmd’
‘vector_name_hashing.Rmd’
Error: Vignette re-building failed.
Execution halted- ERROR10 OK, 3 ERRORNow
- ERROR4 OK, 1 ERROR2026-04-29
Documentation
The repository also keeps web-only articles.
- Help pages
- 10 (1 internal)includes a package overview page
- Examples that run
- 100%1 run in a plain check
- Exported functions with examples
- 11%
- Documented parameters
- 100%
- Return-value docs
- 100%
- Help pages citing references
- 0%
Downloads
Repository
- PRs merged (all time)
- 100%
- Median days to close, 50 most recently updated closed issues
- 1
- Median days to close, 50 most recently updated closed PRs
- 0
Stars over time
Releases over time
Issues over time
PRs over time
Commits over time
8 development-tooling and community-health practices detected across 4 families in the upstream repository
Checks run against github.com/nicchr/cppally on 2026-10-21.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
GitHub Pages site last deployed 2026-10-20 · The repository has a site deploy workflow
pkgdown site last built 2026-10-20
Dependencies
Installing cppally adds no packages beyond those that come with R.
Code & Tests
People & History
Pick two releases to compare their code metrics.
- 1.1.0Latest
- 1.0.0
- 0.1.02026-04-28
- RR 4.6.0 released · 2026-04-24
Package metadata
- First published
- 2026-04-28
- Total releases
- 3 / 1 yrs
- License
- MIT + file LICENSE OSI
- Minimum R
- ≥ 4.5.0
- Download size
- 266 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("cppally")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-23, which the citation names so these numbers can be found later. More on citing and the projects behind them.