/usr/lib/R/site-library/dplyr/include/dplyr/Result/LazyGroupedSubsets.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 126 | #ifndef dplyr_LazyGroupedSubsets_H
#define dplyr_LazyGroupedSubsets_H
#include <tools/SymbolMap.h>
#include <dplyr/GroupedDataFrame.h>
#include <dplyr/SummarisedVariable.h>
#include <dplyr/Result/GroupedSubset.h>
#include <dplyr/Result/ILazySubsets.h>
namespace dplyr {
template <class Data>
class LazySplitSubsets : public ILazySubsets {
typedef typename Data::subset subset;
public:
LazySplitSubsets(const Data& gdf_) :
gdf(gdf_),
subsets(),
symbol_map(),
resolved(),
owner(true)
{
const DataFrame& data = gdf.data();
CharacterVector names = data.names();
int n = data.size();
LOG_INFO << "processing " << n << " vars: " << names;
for (int i = 0; i < n; i++) {
input(names[i], data[i]);
}
}
LazySplitSubsets(const LazySplitSubsets& other) :
gdf(other.gdf),
subsets(other.subsets),
symbol_map(other.symbol_map),
resolved(other.resolved),
owner(false)
{}
virtual ~LazySplitSubsets() {
if (owner) {
for (size_t i = 0; i < subsets.size(); i++) {
delete subsets[i];
}
}
}
public:
virtual const SymbolVector get_variable_names() const {
return symbol_map.get_names();
}
virtual SEXP get_variable(const SymbolString& symbol) const {
return subsets[symbol_map.get(symbol)]->get_variable();
}
virtual SEXP get(const SymbolString& symbol, const SlicingIndex& indices) const {
int idx = symbol_map.get(symbol);
SEXP value = resolved[idx];
if (value == R_NilValue) {
resolved[idx] = value = subsets[idx]->get(indices);
}
return value;
}
virtual bool is_summary(const SymbolString& symbol) const {
return subsets[symbol_map.get(symbol)]->is_summary();
}
virtual bool has_variable(const SymbolString& head) const {
return symbol_map.has(head);
}
virtual void input(const SymbolString& symbol, SEXP x) {
input_subset(symbol, gdf.create_subset(x));
}
virtual int size() const {
return subsets.size();
}
virtual int nrows() const {
return gdf.nrows();
}
public:
void clear() {
for (size_t i = 0; i < resolved.size(); i++) {
resolved[i] = R_NilValue;
}
}
void input_summarised(const SymbolString& symbol, SummarisedVariable x) {
input_subset(symbol, summarised_subset(x));
}
private:
const Data& gdf;
std::vector<subset*> subsets;
SymbolMap symbol_map;
mutable std::vector<SEXP> resolved;
bool owner;
void input_subset(const SymbolString& symbol, subset* sub) {
SymbolMapIndex index = symbol_map.insert(symbol);
if (index.origin == NEW) {
subsets.push_back(sub);
resolved.push_back(R_NilValue);
} else {
int idx = index.pos;
delete subsets[idx];
subsets[idx] = sub;
resolved[idx] = R_NilValue;
}
}
};
typedef LazySplitSubsets<GroupedDataFrame> LazyGroupedSubsets;
}
#endif
|