/usr/lib/R/site-library/dplyr/include/tools/Quosure.h is in r-cran-dplyr 0.7.4-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #ifndef dplyr__Quosure_h
#define dplyr__Quosure_h
#include <tools/SymbolString.h>
#include "SymbolVector.h"
namespace dplyr {
inline SEXP quosure(SEXP expr, SEXP env) {
Language quo("~", expr);
quo.attr(".Environment") = env;
quo.attr("class") = CharacterVector("formula");
return quo;
}
class NamedQuosure {
public:
NamedQuosure(SEXP data_, SymbolString name__ = "") :
data(data_),
name_(name__)
{}
NamedQuosure(const Formula& data_, SymbolString name__ = "") :
data(data_),
name_(name__)
{}
NamedQuosure(const NamedQuosure& other) :
data(other.data),
name_(other.name_)
{}
SEXP expr() const {
return Rf_duplicate(CADR(data));
}
SEXP env() const {
static SEXP sym_dotenv = Rf_install(".Environment");
return Rf_getAttrib(data, sym_dotenv);
}
SymbolString name() const {
return name_;
}
private:
Formula data;
SymbolString name_;
};
} // namespace dplyr
namespace Rcpp {
using namespace dplyr;
template <>
inline bool is<NamedQuosure>(SEXP x) {
bool is_tilde =
TYPEOF(x) == LANGSXP &&
Rf_length(x) == 2 &&
CAR(x) == Rf_install("~");
SEXP env = Rf_getAttrib(x, Rf_install(".Environment"));
bool has_env = TYPEOF(env) == ENVSXP;
return is_tilde && has_env;
}
} // namespace Rcpp
namespace dplyr {
class QuosureList {
public:
QuosureList(const List& data_) : data() {
int n = data_.size();
if (n == 0) return;
CharacterVector names = data_.names();
for (int i = 0; i < n; i++) {
SEXP x = data_[i];
if (!is<NamedQuosure>(x)) {
stop("corrupt tidy quote");
}
data.push_back(NamedQuosure(x, SymbolString(names[i])));
}
}
const NamedQuosure& operator[](int i) const {
return data[i];
}
int size() const {
return data.size();
}
bool single_env() const {
if (data.size() <= 1) return true;
SEXP env = data[0].env();
for (size_t i = 1; i < data.size(); i++) {
if (data[i].env() != env) return false;
}
return true;
}
SymbolVector names() const {
CharacterVector out(data.size());
for (size_t i = 0; i < data.size(); ++i) {
out[i] = data[i].name().get_string();
}
return SymbolVector(out);
}
private:
std::vector<NamedQuosure> data;
};
} // namespace dplyr
#endif
|