Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ jobs:
image: ${{ matrix.config.container }}

steps:
- name: Install sudo package
run: apt update && apt install sudo
- name: Install gh command line tool
uses: wusatosi/setup-gh@v1
- name: Install jq command line tool
uses: vegardit/gha-setup-jq@v1
- name: Install Quarto
uses: quarto-dev/quarto-actions/setup@v2
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/platform-info@v1
with:
Expand All @@ -84,14 +76,6 @@ jobs:
config: ${{ fromJson(needs.setup.outputs.platforms) }}

steps:
- name: Install sudo package
run: apt update && apt install sudo
- name: Install gh command line tool
uses: wusatosi/setup-gh@v1
- name: Install jq command line tool
uses: vegardit/gha-setup-jq@v1
- name: Install Quarto
uses: quarto-dev/quarto-actions/setup@v2
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/setup-r@v1
with:
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ Suggests:
tinysnapshot,
tinytest
LinkingTo:
BH,
cpp11
BH
VignetteBuilder:
quarto
Encoding: UTF-8
Expand Down
26 changes: 26 additions & 0 deletions inst/include/cpp11.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// cpp11 version: 0.5.2
// vendored on: 2025-05-07
#pragma once

#include "cpp11/R.hpp"
#include "cpp11/altrep.hpp"
#include "cpp11/as.hpp"
#include "cpp11/attribute_proxy.hpp"
#include "cpp11/data_frame.hpp"
#include "cpp11/doubles.hpp"
#include "cpp11/environment.hpp"
#include "cpp11/external_pointer.hpp"
#include "cpp11/function.hpp"
#include "cpp11/integers.hpp"
#include "cpp11/list.hpp"
#include "cpp11/list_of.hpp"
#include "cpp11/logicals.hpp"
#include "cpp11/matrix.hpp"
#include "cpp11/named_arg.hpp"
#include "cpp11/protect.hpp"
#include "cpp11/r_bool.hpp"
#include "cpp11/r_string.hpp"
#include "cpp11/r_vector.hpp"
#include "cpp11/raws.hpp"
#include "cpp11/sexp.hpp"
#include "cpp11/strings.hpp"
137 changes: 137 additions & 0 deletions inst/include/cpp11/R.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// cpp11 version: 0.5.2
// vendored on: 2025-05-07
#pragma once

#ifdef R_INTERNALS_H_
#if !(defined(R_NO_REMAP) && defined(STRICT_R_HEADERS))
#error R headers were included before cpp11 headers \
and at least one of R_NO_REMAP or STRICT_R_HEADERS \
was not defined.
#endif
#endif

#ifndef R_NO_REMAP
#define R_NO_REMAP
#endif

#ifndef STRICT_R_HEADERS
#define STRICT_R_HEADERS
#endif

#include "R_ext/Boolean.h"
#include "Rinternals.h"
#include "Rversion.h"

// clang-format off
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wattributes"
#endif

#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wattributes"
#endif
// clang-format on

#include <type_traits>

#if defined(R_VERSION) && R_VERSION >= R_Version(4, 4, 0)
// Use R's new macro
#define CPP11_PRIdXLEN_T R_PRIdXLEN_T
#else
// Recreate what new R does
#ifdef LONG_VECTOR_SUPPORT
#define CPP11_PRIdXLEN_T "td"
#else
#define CPP11_PRIdXLEN_T "d"
#endif
#endif

namespace cpp11 {
namespace literals {

constexpr R_xlen_t operator""_xl(unsigned long long int value) { return value; }

} // namespace literals

namespace traits {
template <typename T>
struct get_underlying_type {
using type = T;
};
} // namespace traits

namespace detail {

// Annoyingly, `TYPEOF()` returns an `int` rather than a `SEXPTYPE`,
// which can throw warnings with `-Wsign-compare` on Windows.
inline SEXPTYPE r_typeof(SEXP x) { return static_cast<SEXPTYPE>(TYPEOF(x)); }

/// Get an object from an environment
///
/// SAFETY: Keep as a pure C function. Call like an R API function, i.e. wrap in `safe[]`
/// as required.
inline SEXP r_env_get(SEXP env, SEXP sym) {
#if defined(R_VERSION) && R_VERSION >= R_Version(4, 5, 0)
const Rboolean inherits = FALSE;
return R_getVar(sym, env, inherits);
#else
SEXP out = Rf_findVarInFrame3(env, sym, TRUE);

// Replicate the 3 checks from `R_getVar()` (along with exact error message):
// - Object must be found in the `env`
// - `R_MissingArg` can't leak from an `env` anymore
// - Promises can't leak from an `env` anymore

if (out == R_MissingArg) {
Rf_errorcall(R_NilValue, "argument \"%s\" is missing, with no default",
CHAR(PRINTNAME(sym)));
}

if (out == R_UnboundValue) {
Rf_errorcall(R_NilValue, "object '%s' not found", CHAR(PRINTNAME(sym)));
}

if (r_typeof(out) == PROMSXP) {
PROTECT(out);
out = Rf_eval(out, env);
UNPROTECT(1);
}

return out;
#endif
}

/// Check if an object exists in an environment
///
/// SAFETY: Keep as a pure C function. Call like an R API function, i.e. wrap in `safe[]`
/// as required.
inline bool r_env_has(SEXP env, SEXP sym) {
#if R_VERSION >= R_Version(4, 2, 0)
return R_existsVarInFrame(env, sym);
#else
return Rf_findVarInFrame3(env, sym, FALSE) != R_UnboundValue;
#endif
}

} // namespace detail

template <typename T>
inline T na();

template <typename T>
inline typename std::enable_if<!std::is_same<typename std::decay<T>::type, double>::value,
bool>::type
is_na(const T& value) {
return value == na<T>();
}

template <typename T>
inline typename std::enable_if<std::is_same<typename std::decay<T>::type, double>::value,
bool>::type
is_na(const T& value) {
return ISNA(value);
}

} // namespace cpp11
8 changes: 8 additions & 0 deletions inst/include/cpp11/altrep.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// cpp11 version: 0.5.2
// vendored on: 2025-05-07
#pragma once

// It would be nice to remove this since all supported versions of R have ALTREP, but
// some groups rely on both this `#define` and `altrep.hpp` itself existing, like arrow:
// https://github.com/r-lib/cpp11/issues/413
#define HAS_ALTREP
Loading