/usr/lib/R/site-library/dplyr/include/dplyr/Result/Processor.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 | #ifndef dplyr_Result_Processor_H
#define dplyr_Result_Processor_H
#include <tools/utils.h>
#include <dplyr/GroupedDataFrame.h>
#include <dplyr/RowwiseDataFrame.h>
#include <dplyr/Result/Result.h>
namespace dplyr {
// if we derive from this instead of deriving from Result, all we have to
// do is implement a process_chunk method that takes a SlicingIndex& as
// input and returns the suitable type (i.e. storage_type<OUTPUT>)
// all the builtin result implementation (Mean, ...) use this.
template <int OUTPUT, typename CLASS>
class Processor : public Result {
public:
typedef typename Rcpp::traits::storage_type<OUTPUT>::type STORAGE;
Processor() : data(R_NilValue) {}
Processor(SEXP data_) : data(data_) {}
virtual SEXP process(const Rcpp::GroupedDataFrame& gdf) {
return process_grouped<GroupedDataFrame>(gdf);
}
virtual SEXP process(const Rcpp::RowwiseDataFrame& gdf) {
return process_grouped<RowwiseDataFrame>(gdf);
}
virtual SEXP process(const Rcpp::FullDataFrame& df) {
return promote(process(df.get_index()));
}
virtual SEXP process(const SlicingIndex& index) {
CLASS* obj = static_cast<CLASS*>(this);
Rcpp::Vector<OUTPUT> res = Rcpp::Vector<OUTPUT>::create(obj->process_chunk(index));
copy_attributes(res, data);
return res;
}
private:
template <typename Data>
SEXP process_grouped(const Data& gdf) {
int n = gdf.ngroups();
Rcpp::Shield<SEXP> res(Rf_allocVector(OUTPUT, n));
STORAGE* ptr = Rcpp::internal::r_vector_start<OUTPUT>(res);
CLASS* obj = static_cast<CLASS*>(this);
typename Data::group_iterator git = gdf.group_begin();
for (int i = 0; i < n; i++, ++git)
ptr[i] = obj->process_chunk(*git);
copy_attributes(res, data);
return res;
}
inline SEXP promote(SEXP obj) {
RObject res(obj);
copy_attributes(res, data);
return res;
}
SEXP data;
};
template <typename CLASS>
class Processor<STRSXP, CLASS> : public Result {
public:
Processor(SEXP data_): data(data_) {}
virtual SEXP process(const Rcpp::GroupedDataFrame& gdf) {
return process_grouped<GroupedDataFrame>(gdf);
}
virtual SEXP process(const Rcpp::RowwiseDataFrame& gdf) {
return process_grouped<RowwiseDataFrame>(gdf);
}
virtual SEXP process(const Rcpp::FullDataFrame& df) {
return process(df.get_index());
}
virtual SEXP process(const SlicingIndex& index) {
CLASS* obj = static_cast<CLASS*>(this);
return CharacterVector::create(obj->process_chunk(index));
}
private:
template <typename Data>
SEXP process_grouped(const Data& gdf) {
int n = gdf.ngroups();
Rcpp::Shield<SEXP> res(Rf_allocVector(STRSXP, n));
CLASS* obj = static_cast<CLASS*>(this);
typename Data::group_iterator git = gdf.group_begin();
for (int i = 0; i < n; i++, ++git)
SET_STRING_ELT(res, i, obj->process_chunk(*git));
return res;
}
SEXP data;
};
}
#endif
|