Skip to content

Commit 6d80be9

Browse files
authored
Merge pull request #40 from tdaverse/fix-cpp11-rchk
Fix cpp11 rchk
2 parents 87ba39a + b0f46f7 commit 6d80be9

27 files changed

+4140
-18
lines changed

.github/workflows/rhub.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ jobs:
5151
image: ${{ matrix.config.container }}
5252

5353
steps:
54-
- name: Install sudo package
55-
run: apt update && apt install sudo
56-
- name: Install gh command line tool
57-
uses: wusatosi/setup-gh@v1
58-
- name: Install jq command line tool
59-
uses: vegardit/gha-setup-jq@v1
60-
- name: Install Quarto
61-
uses: quarto-dev/quarto-actions/setup@v2
6254
- uses: r-hub/actions/checkout@v1
6355
- uses: r-hub/actions/platform-info@v1
6456
with:
@@ -84,14 +76,6 @@ jobs:
8476
config: ${{ fromJson(needs.setup.outputs.platforms) }}
8577

8678
steps:
87-
- name: Install sudo package
88-
run: apt update && apt install sudo
89-
- name: Install gh command line tool
90-
uses: wusatosi/setup-gh@v1
91-
- name: Install jq command line tool
92-
uses: vegardit/gha-setup-jq@v1
93-
- name: Install Quarto
94-
uses: quarto-dev/quarto-actions/setup@v2
9579
- uses: r-hub/actions/checkout@v1
9680
- uses: r-hub/actions/setup-r@v1
9781
with:

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ Suggests:
3232
tinysnapshot,
3333
tinytest
3434
LinkingTo:
35-
BH,
36-
cpp11
35+
BH
3736
VignetteBuilder:
3837
quarto
3938
Encoding: UTF-8

inst/include/cpp11.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// cpp11 version: 0.5.2
2+
// vendored on: 2025-05-07
3+
#pragma once
4+
5+
#include "cpp11/R.hpp"
6+
#include "cpp11/altrep.hpp"
7+
#include "cpp11/as.hpp"
8+
#include "cpp11/attribute_proxy.hpp"
9+
#include "cpp11/data_frame.hpp"
10+
#include "cpp11/doubles.hpp"
11+
#include "cpp11/environment.hpp"
12+
#include "cpp11/external_pointer.hpp"
13+
#include "cpp11/function.hpp"
14+
#include "cpp11/integers.hpp"
15+
#include "cpp11/list.hpp"
16+
#include "cpp11/list_of.hpp"
17+
#include "cpp11/logicals.hpp"
18+
#include "cpp11/matrix.hpp"
19+
#include "cpp11/named_arg.hpp"
20+
#include "cpp11/protect.hpp"
21+
#include "cpp11/r_bool.hpp"
22+
#include "cpp11/r_string.hpp"
23+
#include "cpp11/r_vector.hpp"
24+
#include "cpp11/raws.hpp"
25+
#include "cpp11/sexp.hpp"
26+
#include "cpp11/strings.hpp"

inst/include/cpp11/R.hpp

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// cpp11 version: 0.5.2
2+
// vendored on: 2025-05-07
3+
#pragma once
4+
5+
#ifdef R_INTERNALS_H_
6+
#if !(defined(R_NO_REMAP) && defined(STRICT_R_HEADERS))
7+
#error R headers were included before cpp11 headers \
8+
and at least one of R_NO_REMAP or STRICT_R_HEADERS \
9+
was not defined.
10+
#endif
11+
#endif
12+
13+
#ifndef R_NO_REMAP
14+
#define R_NO_REMAP
15+
#endif
16+
17+
#ifndef STRICT_R_HEADERS
18+
#define STRICT_R_HEADERS
19+
#endif
20+
21+
#include "R_ext/Boolean.h"
22+
#include "Rinternals.h"
23+
#include "Rversion.h"
24+
25+
// clang-format off
26+
#ifdef __clang__
27+
# pragma clang diagnostic push
28+
# pragma clang diagnostic ignored "-Wattributes"
29+
#endif
30+
31+
#ifdef __GNUC__
32+
# pragma GCC diagnostic push
33+
# pragma GCC diagnostic ignored "-Wattributes"
34+
#endif
35+
// clang-format on
36+
37+
#include <type_traits>
38+
39+
#if defined(R_VERSION) && R_VERSION >= R_Version(4, 4, 0)
40+
// Use R's new macro
41+
#define CPP11_PRIdXLEN_T R_PRIdXLEN_T
42+
#else
43+
// Recreate what new R does
44+
#ifdef LONG_VECTOR_SUPPORT
45+
#define CPP11_PRIdXLEN_T "td"
46+
#else
47+
#define CPP11_PRIdXLEN_T "d"
48+
#endif
49+
#endif
50+
51+
namespace cpp11 {
52+
namespace literals {
53+
54+
constexpr R_xlen_t operator""_xl(unsigned long long int value) { return value; }
55+
56+
} // namespace literals
57+
58+
namespace traits {
59+
template <typename T>
60+
struct get_underlying_type {
61+
using type = T;
62+
};
63+
} // namespace traits
64+
65+
namespace detail {
66+
67+
// Annoyingly, `TYPEOF()` returns an `int` rather than a `SEXPTYPE`,
68+
// which can throw warnings with `-Wsign-compare` on Windows.
69+
inline SEXPTYPE r_typeof(SEXP x) { return static_cast<SEXPTYPE>(TYPEOF(x)); }
70+
71+
/// Get an object from an environment
72+
///
73+
/// SAFETY: Keep as a pure C function. Call like an R API function, i.e. wrap in `safe[]`
74+
/// as required.
75+
inline SEXP r_env_get(SEXP env, SEXP sym) {
76+
#if defined(R_VERSION) && R_VERSION >= R_Version(4, 5, 0)
77+
const Rboolean inherits = FALSE;
78+
return R_getVar(sym, env, inherits);
79+
#else
80+
SEXP out = Rf_findVarInFrame3(env, sym, TRUE);
81+
82+
// Replicate the 3 checks from `R_getVar()` (along with exact error message):
83+
// - Object must be found in the `env`
84+
// - `R_MissingArg` can't leak from an `env` anymore
85+
// - Promises can't leak from an `env` anymore
86+
87+
if (out == R_MissingArg) {
88+
Rf_errorcall(R_NilValue, "argument \"%s\" is missing, with no default",
89+
CHAR(PRINTNAME(sym)));
90+
}
91+
92+
if (out == R_UnboundValue) {
93+
Rf_errorcall(R_NilValue, "object '%s' not found", CHAR(PRINTNAME(sym)));
94+
}
95+
96+
if (r_typeof(out) == PROMSXP) {
97+
PROTECT(out);
98+
out = Rf_eval(out, env);
99+
UNPROTECT(1);
100+
}
101+
102+
return out;
103+
#endif
104+
}
105+
106+
/// Check if an object exists in an environment
107+
///
108+
/// SAFETY: Keep as a pure C function. Call like an R API function, i.e. wrap in `safe[]`
109+
/// as required.
110+
inline bool r_env_has(SEXP env, SEXP sym) {
111+
#if R_VERSION >= R_Version(4, 2, 0)
112+
return R_existsVarInFrame(env, sym);
113+
#else
114+
return Rf_findVarInFrame3(env, sym, FALSE) != R_UnboundValue;
115+
#endif
116+
}
117+
118+
} // namespace detail
119+
120+
template <typename T>
121+
inline T na();
122+
123+
template <typename T>
124+
inline typename std::enable_if<!std::is_same<typename std::decay<T>::type, double>::value,
125+
bool>::type
126+
is_na(const T& value) {
127+
return value == na<T>();
128+
}
129+
130+
template <typename T>
131+
inline typename std::enable_if<std::is_same<typename std::decay<T>::type, double>::value,
132+
bool>::type
133+
is_na(const T& value) {
134+
return ISNA(value);
135+
}
136+
137+
} // namespace cpp11

inst/include/cpp11/altrep.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// cpp11 version: 0.5.2
2+
// vendored on: 2025-05-07
3+
#pragma once
4+
5+
// It would be nice to remove this since all supported versions of R have ALTREP, but
6+
// some groups rely on both this `#define` and `altrep.hpp` itself existing, like arrow:
7+
// https://github.com/r-lib/cpp11/issues/413
8+
#define HAS_ALTREP

0 commit comments

Comments
 (0)