├── docs ├── CNAME ├── LICENSE ├── logo.png ├── favicon.ico ├── reference │ └── figures │ │ └── logo.png ├── articles │ └── dplyr_files │ │ └── figure-html │ │ ├── unnamed-chunk-15-1.png │ │ └── unnamed-chunk-20-1.png ├── pkgdown.yml ├── tocBullet.svg ├── link.svg └── pkgdown.js ├── inst ├── db │ └── .gitignore └── include │ ├── dplyr.h │ ├── dplyr │ ├── visitor_set │ │ ├── visitor_set.h │ │ ├── VisitorHash.h │ │ ├── VisitorSetMixin.h │ │ ├── VisitorEqualPredicate.h │ │ ├── VisitorSetHasher.h │ │ ├── VisitorSetEqualPredicate.h │ │ ├── VisitorSetHash.h │ │ ├── VisitorSetLess.h │ │ ├── VisitorSetGreater.h │ │ ├── VisitorSetEqual.h │ │ ├── VisitorSetIndexSet.h │ │ └── VisitorSetIndexMap.h │ ├── visitor.h │ ├── EmptySubset.h │ ├── get_column.h │ ├── workarounds.h │ ├── Hybrid.h │ ├── config.h │ ├── subset_visitor.h │ ├── Result │ │ ├── CallProxy.h │ │ ├── LazyRowwiseSubsets.h │ │ ├── Count.h │ │ ├── CallElementProxy.h │ │ ├── GroupedSubsetBase.h │ │ ├── is_smaller.h │ │ ├── Sd.h │ │ ├── Result.h │ │ ├── VectorSliceVisitor.h │ │ ├── GroupedCallReducer.h │ │ ├── In.h │ │ ├── ILazySubsets.h │ │ ├── CumMax.h │ │ ├── CumMin.h │ │ ├── all.h │ │ ├── Var.h │ │ ├── CumSum.h │ │ └── Mutater.h │ ├── HybridHandler.h │ ├── DataFrameVisitorsIndexMap.h │ ├── SummarisedVariable.h │ ├── main.h │ ├── registration.h │ ├── CharacterVectorOrderer.h │ ├── workarounds │ │ └── xlen.h │ ├── Groups.h │ ├── default_value.h │ ├── OrderVisitor.h │ ├── FullDataFrame.h │ ├── Column.h │ ├── JoinVisitor.h │ ├── white_list.h │ ├── vector_class.h │ ├── HybridHandlerMap.h │ ├── tbl_cpp.h │ ├── VectorVisitor.h │ ├── DataFrameColumnVisitor.h │ ├── dplyr.h │ ├── BoolResult.h │ ├── NamedListAccumulator.h │ ├── DataFrameVisitors.h │ ├── DataFrameColumnSubsetVisitor.h │ ├── train.h │ ├── MultipleVectorVisitors.h │ ├── Replicator.h │ └── SubsetVectorVisitor.h │ ├── dplyr_types.h │ ├── tools │ ├── tools.h │ ├── scalar_type.h │ ├── all_na.h │ ├── debug.h │ ├── rlang-export.h │ ├── wrap_subset.h │ ├── match.h │ ├── collapse.h │ ├── hash.h │ ├── Call.h │ ├── pointer_vector.h │ ├── ShrinkableVector.h │ └── SymbolString.h │ └── solaris │ └── solaris.h ├── src ├── pch.h ├── Makevars.win ├── Makevars ├── rlang.cpp ├── init.cpp ├── rlang-export.c ├── group_by.cpp ├── hybrid_in.cpp └── encoding.cpp ├── tic.R ├── tests ├── testthat │ ├── .gitignore │ ├── helper-torture.R │ ├── test-near.R │ ├── test-astyle.R │ ├── test-overscope.R │ ├── test-tbl.R │ ├── test-union-all.R │ ├── test-data_frame.R │ ├── test-ts.R │ ├── test-DBI.R │ ├── test-internals.r │ ├── helper-groups.R │ ├── test-pull.R │ ├── test-colwise-arrange.R │ ├── test-na-if.R │ ├── test-top-n.R │ ├── test-coalesce.R │ ├── test-between.R │ ├── test-colwise-group-by.R │ ├── test-colwise.R │ ├── test-utils.R │ ├── test-funs-predicates.R │ ├── utf-8.R │ ├── test-n_distinct.R │ ├── test-copying.R │ ├── test-colwise-filter.R │ ├── test-lazyeval-compat.R │ ├── helper-astyle.R │ ├── test-group-size.R │ ├── test-nth-value.R │ ├── test-group-indices.R │ ├── test-rank.R │ └── helper-encoding.R └── testthat.R ├── LICENSE ├── revdep ├── .gitignore ├── drake-deps.R ├── cran.md ├── drake-base.R └── email.md ├── vignettes └── .gitignore ├── .gitattributes ├── data ├── nasa.rda ├── storms.rda ├── starwars.rda ├── band_members.rda ├── band_instruments.rda └── band_instruments2.rda ├── man ├── figures │ └── logo.png ├── common_by.Rd ├── tbl_df.Rd ├── same_src.Rd ├── dr_dplyr.Rd ├── init_logging.Rd ├── dim_desc.Rd ├── src_tbls.Rd ├── sql.Rd ├── groups.Rd ├── with_order.Rd ├── tbl.Rd ├── n_distinct.Rd ├── desc.Rd ├── tbl_vars.Rd ├── add_rownames.Rd ├── near.Rd ├── group_by_prepare.Rd ├── between.Rd ├── failwith.Rd ├── ident.Rd ├── n.Rd ├── group_indices.Rd ├── group_size.Rd ├── cumall.Rd ├── location.Rd ├── src.Rd ├── id.Rd ├── auto_copy.Rd ├── make_tbl.Rd ├── grouped_df.Rd ├── na_if.Rd ├── check_dbplyr.Rd ├── src_local.Rd ├── as.table.tbl_cube.Rd ├── starwars.Rd ├── rowwise.Rd ├── band_members.Rd ├── setops.Rd ├── copy_to.Rd ├── order_by.Rd ├── funs.Rd ├── pull.Rd ├── as.tbl_cube.Rd ├── coalesce.Rd ├── select_vars.Rd ├── tidyeval.Rd ├── nasa.Rd ├── all_vars.Rd ├── vars.Rd ├── lead-lag.Rd ├── storms.Rd ├── progress_estimated.Rd ├── summarise_each.Rd ├── compute.Rd ├── if_else.Rd ├── distinct.Rd ├── explain.Rd └── reexports.Rd ├── R ├── ts.R ├── inline.r ├── desc.r ├── near.R ├── group-size.r ├── failwith.r ├── na_if.R ├── data-starwars.R ├── data-bands.R ├── zzz.r ├── dr.R ├── data-nasa.r ├── data-storms.R ├── utils-tidy-eval.R ├── colwise-arrange.R ├── pull.R ├── utils-expr.R ├── src.r ├── group-indices.R ├── reexport-tibble.r ├── coalesce.R ├── explain.r ├── compute-collect.r ├── hybrid.R ├── sets.r ├── utils-replace-with.R └── colwise-group-by.R ├── codecov.yml ├── .gitignore ├── .Rbuildignore ├── dplyr.Rproj ├── data-raw └── band_members.R ├── ISSUE_TEMPLATE.md ├── LICENSE.md ├── cran-comments.md ├── .travis.yml ├── appveyor.yml └── CONDUCT.md /docs/CNAME: -------------------------------------------------------------------------------- 1 | dplyr.tidyverse.org -------------------------------------------------------------------------------- /inst/db/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /src/pch.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /tic.R: -------------------------------------------------------------------------------- 1 | add_package_checks() 2 | -------------------------------------------------------------------------------- /tests/testthat/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite3 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2013-2015 2 | COPYRIGHT HOLDER: RStudio 3 | -------------------------------------------------------------------------------- /revdep/.gitignore: -------------------------------------------------------------------------------- 1 | checks 2 | library 3 | data.sqlite 4 | -------------------------------------------------------------------------------- /docs/LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2013-2015 2 | COPYRIGHT HOLDER: RStudio 3 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | figure 2 | *.html 3 | *.md 4 | rsconnect 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | /NEWS.md merge=union 2 | /.Rbuildignore merge=union 3 | -------------------------------------------------------------------------------- /data/nasa.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/data/nasa.rda -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/docs/logo.png -------------------------------------------------------------------------------- /data/storms.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/data/storms.rda -------------------------------------------------------------------------------- /tests/testthat/helper-torture.R: -------------------------------------------------------------------------------- 1 | with_gctorture2 <- withr::with_(gctorture2) 2 | -------------------------------------------------------------------------------- /data/starwars.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/data/starwars.rda -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/docs/favicon.ico -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(dplyr) 3 | 4 | test_check("dplyr") 5 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/man/figures/logo.png -------------------------------------------------------------------------------- /data/band_members.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/data/band_members.rda -------------------------------------------------------------------------------- /data/band_instruments.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/data/band_instruments.rda -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | PKG_CPPFLAGS = -I../inst/include -DCOMPILING_DPLYR -DRCPP_USING_UTF8_ERROR_STRING 2 | -------------------------------------------------------------------------------- /data/band_instruments2.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/data/band_instruments2.rda -------------------------------------------------------------------------------- /revdep/drake-deps.R: -------------------------------------------------------------------------------- 1 | source("revdep/drake-base.R") 2 | 3 | drake::make(plan_deps) %>% vis_drake_graph() 4 | -------------------------------------------------------------------------------- /docs/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/docs/reference/figures/logo.png -------------------------------------------------------------------------------- /tests/testthat/test-near.R: -------------------------------------------------------------------------------- 1 | context("near") 2 | 3 | test_that("near accepts nearby fp values", { 4 | expect_true(near(sqrt(2) ^ 2, 2)) 5 | }) 6 | -------------------------------------------------------------------------------- /R/ts.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | filter.ts <- function(.data, ...) { 3 | bad_args(".data", "must be a data source, not a ts object, do you want `stats::filter()`?") 4 | } 5 | -------------------------------------------------------------------------------- /R/inline.r: -------------------------------------------------------------------------------- 1 | inlineCxxPlugin <- Rcpp.plugin.maker( 2 | include.before = "#include ", 3 | package = "dplyr", 4 | LinkingTo = c("Rcpp", "BH", "dplyr") 5 | ) 6 | -------------------------------------------------------------------------------- /docs/articles/dplyr_files/figure-html/unnamed-chunk-15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/docs/articles/dplyr_files/figure-html/unnamed-chunk-15-1.png -------------------------------------------------------------------------------- /docs/articles/dplyr_files/figure-html/unnamed-chunk-20-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/dplyr/master/docs/articles/dplyr_files/figure-html/unnamed-chunk-20-1.png -------------------------------------------------------------------------------- /inst/include/dplyr.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_H 2 | #define dplyr_dplyr_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | # Disable long types from C99 or CPP11 extensions 2 | PKG_CPPFLAGS = -I../inst/include -DCOMPILING_DPLYR -DBOOST_NO_INT64_T -DBOOST_NO_INTEGRAL_INT64_T -DBOOST_NO_LONG_LONG -DRCPP_USING_UTF8_ERROR_STRING 3 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/visitor_set.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_visitor_set_H 2 | #define dplyr_visitor_set_H 3 | 4 | #include 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /tests/testthat/test-astyle.R: -------------------------------------------------------------------------------- 1 | context("astyle") 2 | 3 | test_that("source code formatting", { 4 | skip_on_cran() 5 | skip_on_os("windows") 6 | skip_on_travis() 7 | 8 | expect_warning(astyle("--dry-run"), NA) 9 | }) 10 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_visitor_H 2 | #define dplyr_visitor_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | inline VectorVisitor* visitor(SEXP vec); 9 | 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | patch: 6 | default: 7 | target: 0 8 | threshold: 100 9 | project: 10 | default: 11 | target: 70 12 | threshold: 100 13 | -------------------------------------------------------------------------------- /inst/include/dplyr/EmptySubset.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_EmptySubset_H 2 | #define dplyr_EmptySubset_H 3 | 4 | namespace dplyr { 5 | class EmptySubset { 6 | public: 7 | int size() const { 8 | return 0; 9 | } 10 | }; 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /inst/include/dplyr_types.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // avoid inclusion of package header file 8 | #define dplyr_dplyr_H 9 | -------------------------------------------------------------------------------- /src/rlang.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace dplyr { 5 | namespace internal { 6 | 7 | const rlang_api_ptrs_t& rlang_api() { 8 | static rlang_api_ptrs_t ptrs; 9 | return ptrs; 10 | } 11 | 12 | } // namespace internal 13 | } // namespace dplyr 14 | -------------------------------------------------------------------------------- /inst/include/dplyr/get_column.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_get_column_H 2 | #define dplyr_dplyr_get_column_H 3 | 4 | namespace dplyr { 5 | 6 | SymbolString get_column(SEXP, const Environment&, const ILazySubsets&); 7 | 8 | } 9 | 10 | #endif // #ifndef dplyr_dplyr_get_column_H 11 | -------------------------------------------------------------------------------- /inst/include/dplyr/workarounds.h: -------------------------------------------------------------------------------- 1 | #ifndef DPLYR_WORKAROUND_H 2 | #define DPLYR_WORKAROUND_H 3 | 4 | // installChar was introduced in R 3.2.0 5 | #ifndef installChar 6 | #define installChar(x) Rf_install(CHAR(x)) 7 | #define Rf_installChar installChar 8 | #endif 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /inst/include/dplyr/Hybrid.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_Hybrid_H 2 | #define dplyr_dplyr_Hybrid_H 3 | 4 | namespace dplyr { 5 | class ILazySubsets; 6 | class Result; 7 | 8 | Result* get_handler(SEXP, const ILazySubsets&, const Environment&); 9 | 10 | } 11 | 12 | #endif // dplyr_dplyr_Hybrid_H 13 | -------------------------------------------------------------------------------- /inst/include/dplyr/config.h: -------------------------------------------------------------------------------- 1 | #ifndef DPLYR_CONFIG_H 2 | #define DPLYR_CONFIG_H 3 | 4 | #ifndef DPLYR_MIN_INTERUPT_SIZE 5 | #define DPLYR_MIN_INTERUPT_SIZE 10000 6 | #endif 7 | 8 | #ifndef DPLYR_INTERUPT_TIMES 9 | #define DPLYR_INTERUPT_TIMES 10 10 | #endif 11 | 12 | #endif 13 | 14 | 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /src/*.o 2 | /src/*.o-* 3 | /src/*.d 4 | /src/*.so 5 | *.dll 6 | .RData 7 | .Rproj.user 8 | .Rhistory 9 | inst/doc 10 | .httr-oauth 11 | vignettes/*.R 12 | .DS_Store 13 | /clion-test.R 14 | /BROWSE 15 | /GPATH 16 | /GRTAGS 17 | /GTAGS 18 | /TAGS 19 | /.dir-locals.el 20 | /issues 21 | -------------------------------------------------------------------------------- /inst/include/dplyr/subset_visitor.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_subset_visitor_H 2 | #define dplyr_subset_visitor_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | inline SubsetVectorVisitor* subset_visitor(SEXP vec, const SymbolString& name); 9 | 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/CallProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_CallProxy_H 2 | #define dplyr_CallProxy_H 3 | 4 | #include 5 | #include 6 | 7 | namespace dplyr { 8 | 9 | typedef GroupedCallProxy CallProxy; 10 | 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /inst/include/dplyr/HybridHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_HybridHandler_H 2 | #define dplyr_dplyr_HybridHandler_H 3 | 4 | namespace dplyr { 5 | class ILazySubsets; 6 | class Result; 7 | } 8 | 9 | typedef dplyr::Result* (*HybridHandler)(SEXP, const dplyr::ILazySubsets&, int); 10 | 11 | #endif // dplyr_dplyr_HybridHandlerMap_H 12 | -------------------------------------------------------------------------------- /inst/include/tools/tools.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_tools_tools_H 2 | #define dplyr_tools_tools_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /man/common_by.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/join.r 3 | \name{common_by} 4 | \alias{common_by} 5 | \title{Extract out common by variables} 6 | \usage{ 7 | common_by(by = NULL, x, y) 8 | } 9 | \description{ 10 | Extract out common by variables 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/LazyRowwiseSubsets.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_LazyRowwiseSubsets_H 2 | #define dplyr_LazyRowwiseSubsets_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | namespace dplyr { 9 | 10 | typedef LazySplitSubsets LazyRowwiseSubsets; 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /tests/testthat/test-overscope.R: -------------------------------------------------------------------------------- 1 | context("overscope") 2 | 3 | test_that(".data has strict matching semantics (#2591)", { 4 | expect_error( 5 | data_frame(a = 1) %>% mutate(c = .data$b), 6 | "data" 7 | ) 8 | 9 | expect_error( 10 | data_frame(a = 1:3) %>% group_by(a) %>% mutate(c = .data$b), 11 | "data" 12 | ) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-tbl.R: -------------------------------------------------------------------------------- 1 | context("tbl") 2 | 3 | test_that("tbl_nongroup_vars() excludes group variables", { 4 | cube <- group_by(nasa, month) 5 | expect_identical(tbl_nongroup_vars(cube), setdiff(tbl_vars(cube), "month")) 6 | 7 | gdf <- group_by(mtcars, cyl) 8 | expect_identical(tbl_nongroup_vars(gdf), setdiff(tbl_vars(gdf), "cyl")) 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-union-all.R: -------------------------------------------------------------------------------- 1 | context("union_all") 2 | 3 | test_that("union all on vectors concatenates", { 4 | expect_equal(union_all(1:3, 4:6), 1:6) 5 | }) 6 | 7 | test_that("union all on data frames calls bind rows", { 8 | df1 <- data_frame(x = 1:2) 9 | df2 <- data_frame(y = 1:2) 10 | 11 | expect_equal(union_all(df1, df2), bind_rows(df1, df2)) 12 | }) 13 | -------------------------------------------------------------------------------- /inst/include/dplyr/DataFrameVisitorsIndexMap.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_DataFrameVisitors_map_H 2 | #define dplyr_DataFrameVisitors_map_H 3 | 4 | #include 5 | #include 6 | 7 | namespace dplyr { 8 | 9 | typedef VisitorSetIndexMap< DataFrameVisitors, std::vector > ChunkIndexMap; 10 | 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /inst/include/dplyr/SummarisedVariable.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_SummarisedVariable_H 2 | #define dplyr_SummarisedVariable_H 3 | 4 | namespace dplyr { 5 | 6 | class SummarisedVariable { 7 | public: 8 | SummarisedVariable(SEXP x) : data(x) {} 9 | 10 | inline operator SEXP() const { 11 | return data; 12 | } 13 | private: 14 | SEXP data; 15 | }; 16 | 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | urls: 2 | reference: http://dplyr.tidyverse.org/reference 3 | article: http://dplyr.tidyverse.org/articles 4 | articles: 5 | compatibility: compatibility.html 6 | dplyr: dplyr.html 7 | hybrid-evaluation: internals/hybrid-evaluation.html 8 | programming: programming.html 9 | two-table: two-table.html 10 | window-functions: window-functions.html 11 | 12 | -------------------------------------------------------------------------------- /tests/testthat/test-data_frame.R: -------------------------------------------------------------------------------- 1 | context("data_frame") 2 | 3 | # add_rownames ----------------------------------------------------------- 4 | 5 | test_that("add_rownames keeps the tbl classes (#882)", { 6 | expect_warning( 7 | res <- mtcars %>% add_rownames("Make&Model"), 8 | "Deprecated" 9 | ) 10 | expect_equal(class(res), c("tbl_df", "tbl", "data.frame")) 11 | }) 12 | -------------------------------------------------------------------------------- /inst/include/dplyr/main.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_main_H 2 | #define dplyr_dplyr_main_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | using namespace Rcpp; 14 | 15 | #endif // #ifndef dplyr_dplyr_main_H 16 | -------------------------------------------------------------------------------- /man/tbl_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tbl-df.r 3 | \name{tbl_df} 4 | \alias{tbl_df} 5 | \title{Create a data frame tbl.} 6 | \usage{ 7 | tbl_df(data) 8 | } 9 | \arguments{ 10 | \item{data}{a data frame} 11 | } 12 | \description{ 13 | Deprecated: please use \code{\link[tibble:as_tibble]{tibble::as_tibble()}} instead. 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorHash.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorHash_H 2 | #define dplyr_VisitorHash_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | class VisitorHash { 8 | public: 9 | VisitorHash(const Visitor& v_) : v(v_) {} 10 | 11 | inline size_t operator()(int i) const { 12 | return v.hash(i); 13 | } 14 | 15 | private: 16 | const Visitor& v; 17 | }; 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/Count.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_Count_H 2 | #define dplyr_Result_Count_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | class Count : public Processor { 9 | public: 10 | Count() {} 11 | ~Count() {} 12 | 13 | inline int process_chunk(const SlicingIndex& indices) { 14 | return indices.size(); 15 | } 16 | }; 17 | 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorSetMixin.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_visitor_set_VisitorSetMixin_H 2 | #define dplyr_dplyr_visitor_set_VisitorSetMixin_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #endif // #ifndef dplyr_dplyr_visitor_set_VisitorSetMixin_H 10 | -------------------------------------------------------------------------------- /tests/testthat/test-ts.R: -------------------------------------------------------------------------------- 1 | context("ts") 2 | 3 | test_that("filter and lag throw errors", { 4 | x <- ts(1:10) 5 | 6 | expect_error( 7 | filter(x), 8 | "`.data` must be a data source, not a ts object, do you want `stats::filter()`?", 9 | fixed = TRUE 10 | ) 11 | expect_error( 12 | lag(x), 13 | "`x` must be a vector, not a ts object, do you want `stats::lag()`?", 14 | fixed = TRUE 15 | ) 16 | }) 17 | -------------------------------------------------------------------------------- /inst/include/tools/scalar_type.h: -------------------------------------------------------------------------------- 1 | #ifndef DPLYR_SCALAR_TYPE_H 2 | #define DPLYR_SCALAR_TYPE_H 3 | 4 | namespace dplyr { 5 | 6 | namespace traits { 7 | 8 | template 9 | struct scalar_type { 10 | typedef typename Rcpp::traits::storage_type::type type; 11 | }; 12 | 13 | template <> 14 | struct scalar_type { 15 | typedef String type; 16 | }; 17 | 18 | } 19 | 20 | } 21 | 22 | #endif //DPLYR_SCALAR_TYPE_H 23 | -------------------------------------------------------------------------------- /inst/include/dplyr/registration.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_registration_H 2 | #define dplyr_registration_H 3 | 4 | #include 5 | 6 | #if defined(COMPILING_DPLYR) 7 | 8 | DataFrame build_index_cpp(DataFrame data); 9 | void registerHybridHandler(const char*, HybridHandler); 10 | SEXP get_time_classes(); 11 | SEXP get_date_classes(); 12 | 13 | #else 14 | 15 | #include "dplyr_RcppExports.h" 16 | 17 | #endif 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /tests/testthat/test-DBI.R: -------------------------------------------------------------------------------- 1 | context("DBI") 2 | 3 | test_that("can work directly with DBI connection", { 4 | skip_if_not_installed("RSQLite") 5 | skip_if_not_installed("dbplyr") 6 | 7 | con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") 8 | 9 | df <- tibble(x = 1:10, y = letters[1:10]) 10 | df1 <- copy_to(con, df) 11 | df2 <- tbl(con, "df") 12 | 13 | expect_equal(collect(df1), df) 14 | expect_equal(collect(df2), df) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-internals.r: -------------------------------------------------------------------------------- 1 | context("internals") 2 | 3 | test_that("comparisons works as expected (#275)", { 4 | res <- test_comparisons() 5 | expect_true(all(res)) 6 | }) 7 | 8 | test_that("join_match() works as expected", { 9 | res <- test_matches() 10 | expect_true(all(unlist(res))) 11 | }) 12 | 13 | test_that("wrapping of length values works as expected", { 14 | res <- test_length_wrap() 15 | expect_true(all(res)) 16 | }) 17 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/CallElementProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_CallElementProxy_H 2 | #define dplyr_CallElementProxy_H 3 | 4 | namespace dplyr { 5 | 6 | class CallElementProxy { 7 | public: 8 | CallElementProxy(SEXP symbol_, SEXP object_) : 9 | symbol(symbol_), object(object_) 10 | {} 11 | 12 | inline void set(SEXP value) { 13 | SETCAR(object, value); 14 | } 15 | 16 | SEXP symbol; 17 | SEXP object; 18 | }; 19 | 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /inst/include/tools/all_na.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_tools_all_na_H 2 | #define dplyr_tools_all_na_H 3 | 4 | template 5 | inline bool all_na_impl(const Vector& x) { 6 | return all(is_na(x)).is_true(); 7 | } 8 | 9 | template <> 10 | inline bool all_na_impl(const NumericVector& x) { 11 | return all(is_na(x) & !is_nan(x)).is_true(); 12 | } 13 | 14 | inline bool all_na(SEXP x) { 15 | RCPP_RETURN_VECTOR(all_na_impl, x); 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /R/desc.r: -------------------------------------------------------------------------------- 1 | #' Descending order 2 | #' 3 | #' Transform a vector into a format that will be sorted in descending order. 4 | #' This is useful within [arrange()]. 5 | #' 6 | #' @param x vector to transform 7 | #' @export 8 | #' @examples 9 | #' desc(1:10) 10 | #' desc(factor(letters)) 11 | #' 12 | #' first_day <- seq(as.Date("1910/1/1"), as.Date("1920/1/1"), "years") 13 | #' desc(first_day) 14 | #' 15 | #' starwars %>% arrange(desc(mass)) 16 | desc <- function(x) -xtfrm(x) 17 | -------------------------------------------------------------------------------- /inst/include/dplyr/CharacterVectorOrderer.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_CharacterVectorOrderer_H 2 | #define dplyr_CharacterVectorOrderer_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | class CharacterVectorOrderer { 9 | public: 10 | 11 | CharacterVectorOrderer(const CharacterVector& data_); 12 | 13 | inline IntegerVector get() const { 14 | return orders; 15 | } 16 | 17 | private: 18 | IntegerVector orders; 19 | }; 20 | 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorEqualPredicate.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorEqualPredicate_H 2 | #define dplyr_VisitorEqualPredicate_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | class VisitorEqualPredicate { 8 | public: 9 | VisitorEqualPredicate(const Visitor& v_) : v(v_) {} 10 | 11 | inline bool operator()(int i, int j) const { 12 | return v.equal_or_both_na(i, j); 13 | } 14 | 15 | private: 16 | const Visitor& v; 17 | }; 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /inst/include/dplyr/workarounds/xlen.h: -------------------------------------------------------------------------------- 1 | #ifndef DPLYR_WORKAROUND_XLEN_H 2 | #define DPLYR_WORKAROUND_XLEN_H 3 | 4 | #ifdef LONG_VECTOR_SUPPORT 5 | 6 | namespace Rcpp { 7 | 8 | template <> 9 | inline SEXP wrap(const R_xlen_t& x) { 10 | if (x < -R_SHORT_LEN_MAX || x > R_SHORT_LEN_MAX) { 11 | return Rf_ScalarReal(static_cast(x)); 12 | } 13 | else { 14 | return Rf_ScalarInteger(static_cast(x)); 15 | } 16 | } 17 | 18 | } 19 | 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /tests/testthat/helper-groups.R: -------------------------------------------------------------------------------- 1 | expect_groups <- function(df, groups, info = NULL) { 2 | if (length(groups) == 0L) { 3 | expect_null(groups(df), info = info) 4 | expect_identical(group_vars(df), character(), info = info) 5 | } else { 6 | expect_identical(groups(df), lapply(enc2native(groups), as.name), info = info) 7 | expect_identical(group_vars(df), groups, info = info) 8 | } 9 | } 10 | 11 | expect_no_groups <- function(df) { 12 | expect_groups(df, NULL) 13 | } 14 | -------------------------------------------------------------------------------- /inst/include/dplyr/Groups.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_Groups_H 2 | #define dplyr_dplyr_Groups_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | void check_not_groups(const QuosureList& quosures, const GroupedDataFrame& gdf); 11 | void check_not_groups(const QuosureList& quosures, const RowwiseDataFrame& gdf); 12 | 13 | SEXP strip_group_attributes(SEXP df); 14 | 15 | 16 | #endif // #ifndef dplyr_dplyr_Groups_H 17 | -------------------------------------------------------------------------------- /man/same_src.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/src.r 3 | \name{same_src} 4 | \alias{same_src} 5 | \title{Figure out if two sources are the same (or two tbl have the same source)} 6 | \usage{ 7 | same_src(x, y) 8 | } 9 | \arguments{ 10 | \item{x, y}{src or tbls to test} 11 | } 12 | \value{ 13 | a logical flag 14 | } 15 | \description{ 16 | Figure out if two sources are the same (or two tbl have the same source) 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /R/near.R: -------------------------------------------------------------------------------- 1 | #' Compare two numeric vectors 2 | #' 3 | #' This is a safe way of comparing if two vectors of floating point numbers 4 | #' are (pairwise) equal. This is safer than using `==`, because it has 5 | #' a built in tolerance 6 | #' 7 | #' @param x,y Numeric vectors to compare 8 | #' @param tol Tolerance of comparison. 9 | #' @export 10 | #' @examples 11 | #' sqrt(2) ^ 2 == 2 12 | #' near(sqrt(2) ^ 2, 2) 13 | near <- function(x, y, tol = .Machine$double.eps ^ 0.5) { 14 | abs(x - y) < tol 15 | } 16 | -------------------------------------------------------------------------------- /man/dr_dplyr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dr.R 3 | \name{dr_dplyr} 4 | \alias{dr_dplyr} 5 | \title{Dr Dplyr checks your installation for common problems.} 6 | \usage{ 7 | dr_dplyr() 8 | } 9 | \description{ 10 | Only run this if you are seeing problems, like random crashes. 11 | It's possible for \code{dr_dplyr} to return false positives, so there's no 12 | need to run if all is ok. 13 | } 14 | \examples{ 15 | \dontrun{ 16 | dr_dplyr() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /man/init_logging.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{init_logging} 4 | \alias{init_logging} 5 | \title{Enable internal logging} 6 | \usage{ 7 | init_logging(log_level) 8 | } 9 | \arguments{ 10 | \item{log_level}{A character value, one of "WARN", "INFO", "DEBUG", "VERB", 11 | or "NONE".} 12 | } 13 | \description{ 14 | Log entries, depending on the log level, will be printed to the standard 15 | error stream. 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/dim_desc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-format.r 3 | \name{dim_desc} 4 | \alias{dim_desc} 5 | \title{Describing dimensions} 6 | \usage{ 7 | dim_desc(x) 8 | } 9 | \arguments{ 10 | \item{x}{Object to show dimensions for.} 11 | } 12 | \description{ 13 | Prints the dimensions of an array-like object in a user-friendly manner, 14 | substituting \code{NA} with ?? (for SQL queries). 15 | } 16 | \examples{ 17 | dim_desc(mtcars) 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/src_tbls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/src.r 3 | \name{src_tbls} 4 | \alias{src_tbls} 5 | \title{List all tbls provided by a source.} 6 | \usage{ 7 | src_tbls(x) 8 | } 9 | \arguments{ 10 | \item{x}{a data src.} 11 | } 12 | \description{ 13 | This is a generic method which individual src's will provide methods for. 14 | Most methods will not be documented because it's usually pretty obvious what 15 | possible results will be. 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /inst/include/dplyr/default_value.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_default_value_H 2 | #define dplyr_dplyr_default_value_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | inline typename Rcpp::traits::storage_type::type default_value() { 8 | return Rcpp::Vector::get_na() ; 9 | } 10 | 11 | template <> 12 | inline Rbyte default_value() { 13 | return (Rbyte)0 ; 14 | } 15 | 16 | template <> 17 | inline SEXP default_value() { 18 | return R_NilValue ; 19 | } 20 | 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorSetHasher.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorSetHasher_H 2 | #define dplyr_VisitorSetHasher_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | class VisitorSetHasher { 8 | public: 9 | VisitorSetHasher() : visitors(0) {} 10 | 11 | VisitorSetHasher(VisitorSet* visitors_) : visitors(visitors_) {}; 12 | inline size_t operator()(int i) const { 13 | return visitors->hash(i); 14 | } 15 | 16 | private: 17 | VisitorSet* visitors; 18 | }; 19 | 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /tests/testthat/test-pull.R: -------------------------------------------------------------------------------- 1 | context("pull") 2 | 3 | test_that("default extracts last var from data frame", { 4 | df <- data_frame(x = 1:10, y = 1:10) 5 | expect_equal(pull(df), 1:10) 6 | }) 7 | 8 | test_that("can extract by name, or positive/negative position", { 9 | x <- 1:10 10 | df <- data_frame(x = x, y = runif(10)) 11 | 12 | expect_equal(pull(df, x), x) 13 | expect_equal(pull(df, 1L), x) 14 | expect_equal(pull(df, 1), x) 15 | expect_equal(pull(df, -2), x) 16 | expect_equal(pull(df, -2L), x) 17 | }) 18 | -------------------------------------------------------------------------------- /inst/include/dplyr/OrderVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_OrderVisitor_H 2 | #define dplyr_OrderVisitor_H 3 | 4 | namespace dplyr { 5 | 6 | class OrderVisitor { 7 | public: 8 | virtual ~OrderVisitor() {} 9 | 10 | /** are the elements at indices i and j equal */ 11 | virtual bool equal(int i, int j) const = 0; 12 | 13 | /** is the i element less than the j element */ 14 | virtual bool before(int i, int j) const = 0; 15 | 16 | virtual SEXP get() = 0; 17 | 18 | }; 19 | 20 | } // namespace dplyr 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /inst/include/tools/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_tools_debug_H 2 | #define dplyr_tools_debug_H 3 | 4 | // borrowed from Rcpp11 5 | #ifndef RCPP_DEBUG_OBJECT 6 | #define RCPP_DEBUG_OBJECT(OBJ) Rf_PrintValue( Rf_eval( Rf_lang2( Rf_install( "str"), OBJ ), R_GlobalEnv ) ); 7 | #endif 8 | 9 | #ifndef RCPP_INSPECT_OBJECT 10 | #define RCPP_INSPECT_OBJECT(OBJ) Rf_PrintValue( Rf_eval( Rf_lang2( Rf_install( ".Internal"), Rf_lang2( Rf_install( "inspect" ), OBJ ) ), R_GlobalEnv ) ); 11 | #endif 12 | 13 | #endif // #ifndef dplyr_tools_debug_H 14 | -------------------------------------------------------------------------------- /man/sql.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compat-dbplyr.R 3 | \name{sql} 4 | \alias{sql} 5 | \title{SQL escaping.} 6 | \usage{ 7 | sql(...) 8 | } 9 | \arguments{ 10 | \item{...}{Character vectors that will be combined into a single SQL 11 | expression.} 12 | } 13 | \description{ 14 | These functions are critical when writing functions that translate R 15 | functions to sql functions. Typically a conversion function should escape 16 | all its inputs and return an sql object. 17 | } 18 | -------------------------------------------------------------------------------- /tests/testthat/test-colwise-arrange.R: -------------------------------------------------------------------------------- 1 | context("colwise arrange") 2 | 3 | df <- mtcars[1:3] 4 | 5 | test_that("scoped arrange is identical to manual arrange", { 6 | expect_identical(arrange_all(df), arrange(df, mpg, cyl, disp)) 7 | expect_identical(arrange_at(df, vars(mpg)), arrange(df, mpg)) 8 | expect_identical(arrange_if(iris, is.factor), arrange(iris, Species)) 9 | }) 10 | 11 | test_that(".funs is applied to variables before sorting", { 12 | expect_identical(arrange_all(df, `-`), arrange(df, -mpg, -cyl, -disp)) 13 | }) 14 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/GroupedSubsetBase.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_GroupedSubsetBase_H 2 | #define dplyr_GroupedSubsetBase_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | class GroupedSubset { 9 | public: 10 | GroupedSubset() {}; 11 | virtual ~GroupedSubset() {}; 12 | virtual SEXP get(const SlicingIndex& indices) = 0; 13 | virtual SEXP get_variable() const = 0; 14 | virtual bool is_summary() const = 0; 15 | }; 16 | 17 | typedef GroupedSubset RowwiseSubset; 18 | 19 | } 20 | 21 | #endif //dplyr_GroupedSubsetBase_H 22 | -------------------------------------------------------------------------------- /tests/testthat/test-na-if.R: -------------------------------------------------------------------------------- 1 | context("na_if") 2 | 3 | test_that("error for bad y length", { 4 | expect_error( 5 | na_if(1:3, 1:2), 6 | "`y` must be length 3 (same as `x`) or one, not 2", 7 | fixed = TRUE 8 | ) 9 | 10 | expect_error( 11 | na_if(1, 1:2), 12 | "`y` must be length 1 (same as `x`), not 2", 13 | fixed = TRUE 14 | ) 15 | }) 16 | 17 | test_that("scalar y replaces all matching x", { 18 | x <- c(0, 1, 0) 19 | expect_equal(na_if(x, 0), c(NA, 1, NA)) 20 | expect_equal(na_if(x, 1), c(0, NA, 0)) 21 | }) 22 | -------------------------------------------------------------------------------- /inst/include/dplyr/FullDataFrame.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_tools_FullDataFrame_H 2 | #define dplyr_tools_FullDataFrame_H 3 | 4 | namespace dplyr { 5 | 6 | class FullDataFrame { 7 | public: 8 | typedef NaturalSlicingIndex slicing_index; 9 | 10 | FullDataFrame(const DataFrame& data_) : index(data_.nrows()) {} 11 | 12 | const SlicingIndex& get_index() const { 13 | return index; 14 | } 15 | 16 | inline int nrows() const { 17 | return index.size(); 18 | } 19 | 20 | private: 21 | NaturalSlicingIndex index; 22 | }; 23 | 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /R/group-size.r: -------------------------------------------------------------------------------- 1 | #' Calculate group sizes. 2 | #' 3 | #' @param x a grouped tbl 4 | #' @export 5 | #' @examples 6 | #' if (require("nycflights13")) { 7 | #' 8 | #' by_day <- flights %>% group_by(year, month, day) 9 | #' n_groups(by_day) 10 | #' group_size(by_day) 11 | #' 12 | #' by_dest <- flights %>% group_by(dest) 13 | #' n_groups(by_dest) 14 | #' group_size(by_dest) 15 | #' } 16 | #' @keywords internal 17 | group_size <- function(x) UseMethod("group_size") 18 | 19 | #' @export 20 | #' @rdname group_size 21 | n_groups <- function(x) UseMethod("n_groups") 22 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | .Rprofile 5 | inst/db 6 | man-roxygen 7 | demo/pandas 8 | ^\.httr-oauth$ 9 | ^cran-comments\.md$ 10 | ^README\.Rmd$ 11 | ^revdep$ 12 | ^README-.*\.png$ 13 | ^codecov\.yml$ 14 | ^appveyor\.yml$ 15 | ^Doxyfile$ 16 | ^clion-test\.R$ 17 | ^API$ 18 | ^ISSUE_TEMPLATE\.md$ 19 | ^data-raw$ 20 | ^LICENSE\.md$ 21 | ^BROWSE$ 22 | ^GPATH$ 23 | ^GRTAGS$ 24 | ^GTAGS$ 25 | ^TAGS$ 26 | ^\.dir-locals\.el$ 27 | ^vignettes/rsconnect$ 28 | ^docs$ 29 | ^_pkgdown\.yml$ 30 | ^issues$ 31 | ^tic\.R$ 32 | ^CONDUCT\.md$ 33 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/is_smaller.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_is_smaller_H 2 | #define dplyr_Result_is_smaller_H 3 | 4 | namespace dplyr { 5 | namespace internal { 6 | 7 | template 8 | inline bool is_smaller(typename Rcpp::traits::storage_type::type lhs, typename Rcpp::traits::storage_type::type rhs) { 9 | return lhs < rhs; 10 | } 11 | template <> 12 | inline bool is_smaller(SEXP lhs, SEXP rhs) { 13 | return strcmp(CHAR(lhs), CHAR(rhs)) < 0; 14 | } 15 | 16 | } // namespace internal 17 | } // namespace dplyr 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /inst/include/tools/rlang-export.h: -------------------------------------------------------------------------------- 1 | #ifndef RLANG_EXPORT_H 2 | #define RLANG_EXPORT_H 3 | 4 | #define R_NO_REMAP 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | #if (defined(R_VERSION) && R_VERSION < R_Version(3, 4, 0)) 11 | typedef union { 12 | void* p; 13 | DL_FUNC fn; 14 | } fn_ptr; 15 | SEXP R_MakeExternalPtrFn(DL_FUNC p, SEXP tag, SEXP prot); 16 | DL_FUNC R_ExternalPtrAddrFn(SEXP s); 17 | #endif 18 | 19 | void rlang_register_pointer(const char* ns, const char* ptr_name, DL_FUNC fn); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /man/groups.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/group-by.r 3 | \name{groups} 4 | \alias{groups} 5 | \alias{group_vars} 6 | \title{Return grouping variables} 7 | \usage{ 8 | groups(x) 9 | 10 | group_vars(x) 11 | } 12 | \arguments{ 13 | \item{x}{A \code{\link[=tbl]{tbl()}}} 14 | } 15 | \description{ 16 | \code{group_vars()} returns a character vector; \code{groups()} returns a list of 17 | symbols. 18 | } 19 | \examples{ 20 | df <- tibble(x = 1, y = 2) \%>\% group_by(x, y) 21 | group_vars(df) 22 | groups(df) 23 | } 24 | -------------------------------------------------------------------------------- /man/with_order.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/order-by.R 3 | \name{with_order} 4 | \alias{with_order} 5 | \title{Run a function with one order, translating result back to original order} 6 | \usage{ 7 | with_order(order_by, fun, x, ...) 8 | } 9 | \arguments{ 10 | \item{order_by}{vector to order by} 11 | 12 | \item{fun}{window function} 13 | 14 | \item{x, ...}{arguments to \code{f}} 15 | } 16 | \description{ 17 | This is used to power the ordering parameters of dplyr's window functions 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorSetEqualPredicate.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorSetEqualPredicate_H 2 | #define dplyr_VisitorSetEqualPredicate_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | class VisitorSetEqualPredicate { 8 | public: 9 | VisitorSetEqualPredicate() : visitors(0) {} 10 | 11 | VisitorSetEqualPredicate(VisitorSet* visitors_) : visitors(visitors_) {}; 12 | inline bool operator()(int i, int j) const { 13 | return visitors->equal(i, j); 14 | } 15 | 16 | private: 17 | VisitorSet* visitors; 18 | }; 19 | 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /tests/testthat/test-top-n.R: -------------------------------------------------------------------------------- 1 | context("top_n") 2 | 3 | test_that("top_n returns n rows", { 4 | test_df <- data.frame(x = 1:10, y = 11:20) 5 | top_four <- test_df %>% top_n(4, y) 6 | expect_equal(dim(top_four), c(4, 2)) 7 | }) 8 | 9 | test_that("top_n() handles missing `wt`", { 10 | df <- data.frame(x = c(10, 4, 1, 6, 3, 1, 1)) 11 | expect_message(regexp = "Selecting by x", 12 | expect_identical(top_n(df, 2)$x, c(10, 6)) 13 | ) 14 | }) 15 | 16 | test_that("top_n() handles calls", { 17 | expect_identical(top_n(mtcars, 2, -disp), top_n(mtcars, -2, disp)) 18 | }) 19 | -------------------------------------------------------------------------------- /inst/include/tools/wrap_subset.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_wrap_subset_H 2 | #define dplyr_wrap_subset_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | SEXP wrap_subset(SEXP input, const Container& indices) { 8 | int n = indices.size(); 9 | Rcpp::Vector res = Rcpp::no_init(n); 10 | typedef typename Rcpp::traits::storage_type::type STORAGE; 11 | STORAGE* ptr = Rcpp::internal::r_vector_start(input); 12 | for (int i = 0; i < n; i++) 13 | res[i] = ptr[ indices[i] ]; 14 | return res; 15 | } 16 | 17 | } 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /man/tbl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tbl.r 3 | \name{tbl} 4 | \alias{tbl} 5 | \alias{is.tbl} 6 | \alias{as.tbl} 7 | \title{Create a table from a data source} 8 | \usage{ 9 | tbl(src, ...) 10 | 11 | is.tbl(x) 12 | 13 | as.tbl(x, ...) 14 | } 15 | \arguments{ 16 | \item{src}{A data source} 17 | 18 | \item{...}{Other arguments passed on to the individual methods} 19 | 20 | \item{x}{an object to coerce to a \code{tbl}} 21 | } 22 | \description{ 23 | This is a generic method that dispatches based on the first argument. 24 | } 25 | -------------------------------------------------------------------------------- /R/failwith.r: -------------------------------------------------------------------------------- 1 | #' Fail with specified value. 2 | #' 3 | #' Deprecated. Please use [purrr::possibly()] instead. 4 | #' 5 | #' @param default default value 6 | #' @param f function 7 | #' @param quiet all error messages be suppressed? 8 | #' @return a function 9 | #' @seealso [plyr::try_default()] 10 | #' @keywords internal 11 | #' @export 12 | failwith <- function(default = NULL, f, quiet = FALSE) { 13 | warn("Deprecated: please use `purrr::possibly()` instead") 14 | 15 | function(...) { 16 | out <- default 17 | try(out <- f(...), silent = quiet) 18 | out 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dplyr.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | QuitChildProcessesOnExit: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | StripTrailingWhitespace: Yes 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source --install-tests 22 | PackageBuildArgs: --no-build-vignettes 23 | PackageRoxygenize: rd,collate,namespace 24 | -------------------------------------------------------------------------------- /inst/include/dplyr/Column.h: -------------------------------------------------------------------------------- 1 | #ifndef DPLYR_DPLYR_COLUMN_H 2 | #define DPLYR_DPLYR_COLUMN_H 3 | 4 | class Column { 5 | public: 6 | Column(SEXP data_, const SymbolString& name_) : data(data_), name(name_) {} 7 | 8 | public: 9 | const RObject& get_data() const { 10 | return data; 11 | } 12 | 13 | const SymbolString& get_name() const { 14 | return name; 15 | } 16 | 17 | Column update_data(SEXP new_data) const { 18 | return Column(new_data, name); 19 | } 20 | 21 | private: 22 | RObject data; 23 | SymbolString name; 24 | }; 25 | 26 | #endif //DPLYR_DPLYR_COLUMN_H 27 | -------------------------------------------------------------------------------- /tests/testthat/test-coalesce.R: -------------------------------------------------------------------------------- 1 | context("coalesce") 2 | 3 | test_that("non-missing scalar replaces all missing values", { 4 | x <- c(NA, 1) 5 | expect_equal(coalesce(x, 1), c(1, 1)) 6 | }) 7 | 8 | test_that("finds non-missing values in multiple positions", { 9 | x1 <- c(1L, NA, NA) 10 | x2 <- c(NA, 2L, NA) 11 | x3 <- c(NA, NA, 3L) 12 | 13 | expect_equal(coalesce(x1, x2, x3), 1:3) 14 | }) 15 | 16 | test_that("error if invalid length", { 17 | expect_error( 18 | coalesce(1:2, 1:3), 19 | "Argument 2 must be length 2 (length of `x`) or one, not 3", 20 | fixed = TRUE 21 | ) 22 | }) 23 | -------------------------------------------------------------------------------- /data-raw/band_members.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | band_members <- tribble( 4 | ~name, ~band, 5 | "Mick", "Stones", 6 | "John", "Beatles", 7 | "Paul", "Beatles" 8 | ) 9 | 10 | devtools::use_data(band_members) 11 | 12 | band_instruments <- tribble( 13 | ~name, ~plays, 14 | "John", "guitar", 15 | "Paul", "bass", 16 | "Keith", "guitar" 17 | ) 18 | 19 | devtools::use_data(band_instruments) 20 | 21 | band_instruments2 <- tribble( 22 | ~artist, ~plays, 23 | "John", "guitar", 24 | "Paul", "bass", 25 | "Keith", "guitar" 26 | ) 27 | 28 | devtools::use_data(band_instruments2) 29 | -------------------------------------------------------------------------------- /man/n_distinct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/distinct.R 3 | \name{n_distinct} 4 | \alias{n_distinct} 5 | \title{Efficiently count the number of unique values in a set of vector} 6 | \usage{ 7 | n_distinct(..., na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{\dots}{vectors of values} 11 | 12 | \item{na.rm}{if \code{TRUE} missing values don't count} 13 | } 14 | \description{ 15 | This is a faster and more concise equivalent of \code{length(unique(x))} 16 | } 17 | \examples{ 18 | x <- sample(1:10, 1e5, rep = TRUE) 19 | length(unique(x)) 20 | n_distinct(x) 21 | } 22 | -------------------------------------------------------------------------------- /man/desc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/desc.r 3 | \name{desc} 4 | \alias{desc} 5 | \title{Descending order} 6 | \usage{ 7 | desc(x) 8 | } 9 | \arguments{ 10 | \item{x}{vector to transform} 11 | } 12 | \description{ 13 | Transform a vector into a format that will be sorted in descending order. 14 | This is useful within \code{\link[=arrange]{arrange()}}. 15 | } 16 | \examples{ 17 | desc(1:10) 18 | desc(factor(letters)) 19 | 20 | first_day <- seq(as.Date("1910/1/1"), as.Date("1920/1/1"), "years") 21 | desc(first_day) 22 | 23 | starwars \%>\% arrange(desc(mass)) 24 | } 25 | -------------------------------------------------------------------------------- /man/tbl_vars.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tbl.r 3 | \name{tbl_vars} 4 | \alias{tbl_vars} 5 | \alias{tbl_nongroup_vars} 6 | \title{List variables provided by a tbl.} 7 | \usage{ 8 | tbl_vars(x) 9 | 10 | tbl_nongroup_vars(x) 11 | } 12 | \arguments{ 13 | \item{x}{A tbl object} 14 | } 15 | \description{ 16 | \code{tbl_vars()} returns all variables while \code{tbl_nongroup_vars()} 17 | returns only non-grouping variables. 18 | } 19 | \seealso{ 20 | \code{\link[=group_vars]{group_vars()}} for a function that returns grouping 21 | variables. 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/add_rownames.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dataframe.R 3 | \name{add_rownames} 4 | \alias{add_rownames} 5 | \title{Convert row names to an explicit variable.} 6 | \usage{ 7 | add_rownames(df, var = "rowname") 8 | } 9 | \arguments{ 10 | \item{df}{Input data frame with rownames.} 11 | 12 | \item{var}{Name of variable to use} 13 | } 14 | \description{ 15 | Deprecated, use \code{\link[tibble:rownames_to_column]{tibble::rownames_to_column()}} instead. 16 | } 17 | \examples{ 18 | mtcars \%>\% tbl_df() 19 | 20 | mtcars \%>\% add_rownames() 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/near.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/near.R 3 | \name{near} 4 | \alias{near} 5 | \title{Compare two numeric vectors} 6 | \usage{ 7 | near(x, y, tol = .Machine$double.eps^0.5) 8 | } 9 | \arguments{ 10 | \item{x, y}{Numeric vectors to compare} 11 | 12 | \item{tol}{Tolerance of comparison.} 13 | } 14 | \description{ 15 | This is a safe way of comparing if two vectors of floating point numbers 16 | are (pairwise) equal. This is safer than using \code{==}, because it has 17 | a built in tolerance 18 | } 19 | \examples{ 20 | sqrt(2) ^ 2 == 2 21 | near(sqrt(2) ^ 2, 2) 22 | } 23 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/Sd.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_Sd_H 2 | #define dplyr_Result_Sd_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | template 9 | class Sd : public Processor > { 10 | public: 11 | typedef Processor > Base; 12 | 13 | Sd(SEXP x) : 14 | Base(x), 15 | var(x) 16 | {} 17 | ~Sd() {} 18 | 19 | inline double process_chunk(const SlicingIndex& indices) { 20 | return sqrt(var.process_chunk(indices)); 21 | } 22 | 23 | private: 24 | Var var; 25 | }; 26 | 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /man/group_by_prepare.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/group-by.r 3 | \name{group_by_prepare} 4 | \alias{group_by_prepare} 5 | \title{Prepare for grouping.} 6 | \usage{ 7 | group_by_prepare(.data, ..., .dots = list(), add = FALSE) 8 | } 9 | \value{ 10 | A list 11 | \item{data}{Modified tbl} 12 | \item{groups}{Modified groups} 13 | } 14 | \description{ 15 | Performs standard operations that should happen before individual methods 16 | process the data. This includes mutating the tbl to add new grouping columns 17 | and updating the groups (based on add) 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/between.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{between} 4 | \alias{between} 5 | \title{Do values in a numeric vector fall in specified range?} 6 | \usage{ 7 | between(x, left, right) 8 | } 9 | \arguments{ 10 | \item{x}{A numeric vector of values} 11 | 12 | \item{left, right}{Boundary values} 13 | } 14 | \description{ 15 | This is a shortcut for \code{x >= left & x <= right}, implemented 16 | efficiently in C++ for local values, and translated to the 17 | appropriate SQL for remote tables. 18 | } 19 | \examples{ 20 | x <- rnorm(1e2) 21 | x[between(x, -1, 1)] 22 | } 23 | -------------------------------------------------------------------------------- /man/failwith.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/failwith.r 3 | \name{failwith} 4 | \alias{failwith} 5 | \title{Fail with specified value.} 6 | \usage{ 7 | failwith(default = NULL, f, quiet = FALSE) 8 | } 9 | \arguments{ 10 | \item{default}{default value} 11 | 12 | \item{f}{function} 13 | 14 | \item{quiet}{all error messages be suppressed?} 15 | } 16 | \value{ 17 | a function 18 | } 19 | \description{ 20 | Deprecated. Please use \code{\link[purrr:possibly]{purrr::possibly()}} instead. 21 | } 22 | \seealso{ 23 | \code{\link[plyr:try_default]{plyr::try_default()}} 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/ident.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compat-dbplyr.R 3 | \name{ident} 4 | \alias{ident} 5 | \title{Flag a character vector as SQL identifiers} 6 | \usage{ 7 | ident(...) 8 | } 9 | \arguments{ 10 | \item{...}{A character vector, or name-value pairs} 11 | } 12 | \description{ 13 | \code{ident()} takes unquoted strings and flags them as identifiers. 14 | \code{ident_q()} assumes its input has already been quoted, and ensures 15 | it does not get quoted again. This is currently used only for 16 | for \code{schema.table}. 17 | } 18 | \examples{ 19 | # Identifiers are escaped with " 20 | ident("x") 21 | } 22 | -------------------------------------------------------------------------------- /man/n.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/manip.r 3 | \name{n} 4 | \alias{n} 5 | \title{The number of observations in the current group.} 6 | \usage{ 7 | n() 8 | } 9 | \description{ 10 | This function is implemented specifically for each data source and can only 11 | be used from within \code{\link[=summarise]{summarise()}}, \code{\link[=mutate]{mutate()}} and 12 | \code{\link[=filter]{filter()}}. 13 | } 14 | \examples{ 15 | if (require("nycflights13")) { 16 | carriers <- group_by(flights, carrier) 17 | summarise(carriers, n()) 18 | mutate(carriers, n = n()) 19 | filter(carriers, n() < 100) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /man/group_indices.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/group-indices.R 3 | \name{group_indices} 4 | \alias{group_indices} 5 | \title{Group id.} 6 | \usage{ 7 | group_indices(.data, ...) 8 | } 9 | \arguments{ 10 | \item{.data}{a tbl} 11 | 12 | \item{...}{Variables to group by. All tbls accept variable names. 13 | Some tbls will accept functions of variables. Duplicated groups 14 | will be silently dropped.} 15 | } 16 | \description{ 17 | Generate a unique id for each group 18 | } 19 | \examples{ 20 | group_indices(mtcars, cyl) 21 | } 22 | \seealso{ 23 | \code{\link[=group_by]{group_by()}} 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/group_size.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/group-size.r 3 | \name{group_size} 4 | \alias{group_size} 5 | \alias{n_groups} 6 | \title{Calculate group sizes.} 7 | \usage{ 8 | group_size(x) 9 | 10 | n_groups(x) 11 | } 12 | \arguments{ 13 | \item{x}{a grouped tbl} 14 | } 15 | \description{ 16 | Calculate group sizes. 17 | } 18 | \examples{ 19 | if (require("nycflights13")) { 20 | 21 | by_day <- flights \%>\% group_by(year, month, day) 22 | n_groups(by_day) 23 | group_size(by_day) 24 | 25 | by_dest <- flights \%>\% group_by(dest) 26 | n_groups(by_dest) 27 | group_size(by_dest) 28 | } 29 | } 30 | \keyword{internal} 31 | -------------------------------------------------------------------------------- /man/cumall.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{cumall} 4 | \alias{cumall} 5 | \alias{cumany} 6 | \alias{cummean} 7 | \title{Cumulativate versions of any, all, and mean} 8 | \usage{ 9 | cumall(x) 10 | 11 | cumany(x) 12 | 13 | cummean(x) 14 | } 15 | \arguments{ 16 | \item{x}{For \code{cumall()} and \code{cumany()}, a logical vector; for 17 | \code{cummean()} an integer or numeric vector} 18 | } 19 | \description{ 20 | dplyr adds \code{cumall()}, \code{cumany()}, and \code{cummean()} to complete 21 | R's set of cumulate functions to match the aggregation functions available 22 | in most databases 23 | } 24 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorSetHash.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorSetHash_H 2 | #define dplyr_VisitorSetHash_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | template 9 | class VisitorSetHash { 10 | public: 11 | size_t hash(int j) const { 12 | const Class& obj = static_cast(*this); 13 | int n = obj.size(); 14 | if (n == 0) { 15 | stop("Need at least one column for `hash()`"); 16 | } 17 | size_t seed = obj.get(0)->hash(j); 18 | for (int k = 1; k < n; k++) { 19 | boost::hash_combine(seed, obj.get(k)->hash(j)); 20 | } 21 | return seed; 22 | } 23 | }; 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /tests/testthat/test-between.R: -------------------------------------------------------------------------------- 1 | context("between") 2 | 3 | test_that("returns NA if any argument is NA", { 4 | expect_equal(between(1, 1, NA), NA) 5 | expect_equal(between(1, NA, 1), NA) 6 | expect_equal(between(NA, 1, 1), NA) 7 | }) 8 | 9 | test_that("compatible with base R", { 10 | x <- runif(1e3) 11 | expect_equal(between(x, 0.25, 0.5), x >= 0.25 & x <= 0.5) 12 | }) 13 | 14 | test_that("warns when called on S3 object", { 15 | expect_warning(between(factor(1:5), 1, 3), "numeric vector with S3 class") 16 | }) 17 | 18 | test_that("unless it's a date or date time", { 19 | expect_warning(between(Sys.Date(), 1, 3), NA) 20 | expect_warning(between(Sys.time(), 1, 3), NA) 21 | }) 22 | -------------------------------------------------------------------------------- /man/location.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/location.R 3 | \name{location} 4 | \alias{location} 5 | \alias{changes} 6 | \title{Print the location in memory of a data frame} 7 | \usage{ 8 | location(df) 9 | 10 | changes(x, y) 11 | } 12 | \arguments{ 13 | \item{df}{a data frame} 14 | 15 | \item{x, y}{two data frames to compare} 16 | } 17 | \description{ 18 | This is useful for understand how and when dplyr makes copies of data 19 | frames 20 | } 21 | \examples{ 22 | location(mtcars) 23 | 24 | mtcars2 <- mutate(mtcars, cyl2 = cyl * 2) 25 | location(mtcars2) 26 | 27 | changes(mtcars, mtcars) 28 | changes(mtcars, mtcars2) 29 | } 30 | \keyword{internal} 31 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/Result.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_H 2 | #define dplyr_Result_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace dplyr { 10 | 11 | class Result { 12 | public: 13 | Result() {} 14 | 15 | virtual ~Result() {}; 16 | 17 | virtual SEXP process(const RowwiseDataFrame& gdf) = 0; 18 | 19 | virtual SEXP process(const GroupedDataFrame& gdf) = 0; 20 | 21 | virtual SEXP process(const FullDataFrame& df) = 0; 22 | 23 | virtual SEXP process(const SlicingIndex&) { 24 | return R_NilValue; 25 | } 26 | 27 | }; 28 | 29 | } // namespace dplyr 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /inst/include/dplyr/JoinVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_JoinVisitor_H 2 | #define dplyr_JoinVisitor_H 3 | 4 | #include 5 | #include 6 | 7 | namespace dplyr { 8 | 9 | class DataFrameJoinVisitors; 10 | 11 | class JoinVisitor { 12 | public: 13 | virtual ~JoinVisitor() {} 14 | 15 | virtual size_t hash(int i) = 0; 16 | virtual bool equal(int i, int j) = 0; 17 | 18 | virtual SEXP subset(const std::vector& indices) = 0; 19 | virtual SEXP subset(const VisitorSetIndexSet& set) = 0; 20 | 21 | }; 22 | 23 | JoinVisitor* join_visitor(const Column& left, const Column& right, bool warn, bool accept_na_match = true); 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /inst/include/dplyr/white_list.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_white_list_H 2 | #define dplyr_white_list_H 3 | 4 | namespace dplyr { 5 | 6 | inline bool white_list(SEXP x) { 7 | if (Rf_isMatrix(x)) { 8 | // might have to refine later 9 | return true; 10 | } 11 | switch (TYPEOF(x)) { 12 | case RAWSXP: 13 | return true; 14 | case INTSXP: 15 | return true; 16 | case REALSXP: 17 | return true; 18 | case LGLSXP: 19 | return true; 20 | case STRSXP: 21 | return true; 22 | case CPLXSXP: 23 | return true; 24 | case VECSXP: { 25 | if (Rf_inherits(x, "POSIXlt")) return false; 26 | return true; 27 | } 28 | 29 | default: 30 | break; 31 | } 32 | return false; 33 | } 34 | 35 | } 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /docs/tocBullet.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /inst/include/solaris/solaris.h: -------------------------------------------------------------------------------- 1 | #ifndef DPLYR_SOLARIS_H 2 | #define DPLYR_SOLARIS_H 3 | 4 | #if defined(__SUNPRO_CC) && !defined(Rcpp__platform__solaris_h) 5 | 6 | namespace Rcpp { 7 | namespace traits { 8 | 9 | template struct is_convertible< std::vector, SEXP> : public false_type {}; 10 | template <> struct is_convertible : public false_type {}; 11 | 12 | template 13 | struct is_convertible< sugar::Minus_Vector_Primitive< RTYPE, NA, Vector >, SEXP> : public false_type {}; 14 | 15 | template 16 | struct is_convertible< sugar::Plus_Vector_Primitive< RTYPE, NA, Vector >, SEXP> : public false_type {}; 17 | 18 | } 19 | } 20 | 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /inst/include/tools/match.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_tools_match_h 2 | #define dplyr_tools_match_h 3 | 4 | 5 | namespace dplyr { 6 | 7 | inline IntegerVector r_match(SEXP x, SEXP y, SEXP incomparables = R_NilValue) { 8 | static Function match("match", R_BaseEnv); 9 | if (R_VERSION == R_Version(3, 3, 0)) { 10 | // Work around matching bug in R 3.3.0: #1806 11 | // https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16885 12 | if (Rf_isNull(incomparables)) { 13 | return match(x, y, NA_INTEGER, LogicalVector()); 14 | } 15 | else { 16 | return match(x, y, NA_INTEGER, incomparables); 17 | } 18 | } 19 | else { 20 | return match(x, y, NA_INTEGER, incomparables); 21 | } 22 | } 23 | 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /man/src.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/src.r 3 | \name{src} 4 | \alias{src} 5 | \alias{is.src} 6 | \title{Create a "src" object} 7 | \usage{ 8 | src(subclass, ...) 9 | 10 | is.src(x) 11 | } 12 | \arguments{ 13 | \item{subclass}{name of subclass. "src" is an abstract base class, so you 14 | must supply this value. \code{src_} is automatically prepended to the 15 | class name} 16 | 17 | \item{...}{fields used by object. 18 | 19 | These dots are evaluated with \link[rlang:dots_list]{explicit splicing}.} 20 | 21 | \item{x}{object to test for "src"-ness.} 22 | } 23 | \description{ 24 | \code{src()} is the standard constructor for srcs and \code{is.src()} tests. 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /tests/testthat/test-colwise-group-by.R: -------------------------------------------------------------------------------- 1 | context("colwise group_by") 2 | 3 | test_that("group_by_ verbs take scoped inputs", { 4 | expect_identical(group_vars(group_by_all(mtcars)), names(mtcars)) 5 | expect_identical(group_vars(group_by_at(mtcars, vars(starts_with("d")))), c("disp", "drat")) 6 | expect_identical(group_vars(group_by_if(iris, is.factor)), "Species") 7 | }) 8 | 9 | test_that("group_by_ verbs accept optional operations", { 10 | df <- data_frame(x = 1:2, y = 2:3) 11 | gdf <- group_by(mutate_all(df, as.factor), x, y) 12 | 13 | expect_identical(group_by_all(df, as.factor), gdf) 14 | expect_identical(group_by_if(df, is_integer, as.factor), gdf) 15 | expect_identical(group_by_at(df, vars(x:y), as.factor), gdf) 16 | }) 17 | -------------------------------------------------------------------------------- /man/id.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/id.r 3 | \name{id} 4 | \alias{id} 5 | \title{Compute a unique numeric id for each unique row in a data frame.} 6 | \usage{ 7 | id(.variables, drop = FALSE) 8 | } 9 | \arguments{ 10 | \item{.variables}{list of variables} 11 | 12 | \item{drop}{drop unused factor levels?} 13 | } 14 | \value{ 15 | a numeric vector with attribute n, giving total number of 16 | possibilities 17 | } 18 | \description{ 19 | Properties: 20 | \itemize{ 21 | \item \code{order(id)} is equivalent to \code{do.call(order, df)} 22 | \item rows containing the same data have the same value 23 | \item if \code{drop = FALSE} then room for all possibilities 24 | } 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /tests/testthat/test-colwise.R: -------------------------------------------------------------------------------- 1 | context("colwise utils") 2 | 3 | test_that("tbl_at_vars() errs on bad input", { 4 | expect_error( 5 | tbl_at_vars(iris, raw(3)), 6 | "`.vars` must be a character/numeric vector or a `vars()` object, not raw", 7 | fixed = TRUE 8 | ) 9 | }) 10 | 11 | test_that("tbl_at_vars() treats `NULL` as empty inputs", { 12 | expect_identical(tbl_at_vars(mtcars, vars(NULL)), tbl_at_vars(mtcars, vars())) 13 | expect_identical(mutate_at(mtcars, vars(NULL), `*`, 100), mtcars) 14 | }) 15 | 16 | test_that("tbl_if_vars() errs on bad input", { 17 | expect_error( 18 | tbl_if_vars(iris, funs(identity, force), environment()), 19 | "`.predicate` must have length 1, not 2", 20 | fixed = TRUE 21 | ) 22 | }) 23 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorSetLess.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorSetLess_H 2 | #define dplyr_VisitorSetLess_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | class VisitorSetLess { 8 | public: 9 | bool less(int i, int j) const { 10 | if (i == j) return false; 11 | const Class& obj = static_cast(*this); 12 | int n = obj.size(); 13 | for (int k = 0; k < n; k++) { 14 | typename Class::visitor_type* visitor = obj.get(k); 15 | if (! visitor->equal(i, j)) { 16 | return visitor->less(i, j); 17 | } 18 | } 19 | // if we end up here, it means rows i and j are equal 20 | // we break the tie using the indices 21 | return i < j; 22 | } 23 | }; 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /tests/testthat/test-utils.R: -------------------------------------------------------------------------------- 1 | context("utils") 2 | 3 | test_that("check_pkg() gives correct error message", { 4 | expect_error( 5 | dplyr:::check_pkg("`__foobarbaz__`", "foobar a baz"), 6 | 'The `__foobarbaz__` package is required to foobar a baz.\nPlease install it with `install.packages("`__foobarbaz__`")`', 7 | fixed = TRUE 8 | ) 9 | expect_error( 10 | dplyr:::check_pkg("`__foobarbaz__`", "foobar a baz", install = FALSE), 11 | "The `__foobarbaz__` package is required to foobar a baz." 12 | ) 13 | }) 14 | 15 | test_that("get_vars() handles list of symbols as vars attribute", { 16 | gdf <- group_by(tibble(g = 1:2), g) 17 | gdf <- set_attrs(gdf, vars = list(sym("g"))) 18 | expect_identical(test_grouped_df(gdf), gdf) 19 | }) 20 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorSetGreater.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorSetGreater_H 2 | #define dplyr_VisitorSetGreater_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | class VisitorSetGreater { 8 | public: 9 | bool greater(int i, int j) const { 10 | if (i == j) return false; 11 | const Class& obj = static_cast(*this); 12 | int n = obj.size(); 13 | for (int k = 0; k < n; k++) { 14 | typename Class::visitor_type* visitor = obj.get(k); 15 | if (! visitor->equal(i, j)) { 16 | return visitor->greater(i, j); 17 | } 18 | } 19 | // if we end up here, it means rows i and j are equal 20 | // we break the tie using the indices 21 | return i < j; 22 | } 23 | }; 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /man/auto_copy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/copy-to.r 3 | \name{auto_copy} 4 | \alias{auto_copy} 5 | \title{Copy tables to same source, if necessary} 6 | \usage{ 7 | auto_copy(x, y, copy = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x, y}{\code{y} will be copied to \code{x}, if necessary.} 11 | 12 | \item{copy}{If \code{x} and \code{y} are not from the same data source, 13 | and \code{copy} is \code{TRUE}, then \code{y} will be copied into the 14 | same src as \code{x}. This allows you to join tables across srcs, but 15 | it is a potentially expensive operation so you must opt into it.} 16 | 17 | \item{...}{Other arguments passed on to methods.} 18 | } 19 | \description{ 20 | Copy tables to same source, if necessary 21 | } 22 | -------------------------------------------------------------------------------- /tests/testthat/test-funs-predicates.R: -------------------------------------------------------------------------------- 1 | context("funs-predicates") 2 | 3 | test_that("all_exprs() creates intersection", { 4 | expect_identical(all_exprs(am == 1), quo(am == 1)) 5 | 6 | quo <- set_env(quo((!! quo(cyl == 2)) & (!! quo(am == 1))), base_env()) 7 | expect_identical(all_exprs(cyl == 2, am == 1), quo) 8 | }) 9 | 10 | test_that("any_exprs() creates union", { 11 | expect_identical(any_exprs(am == 1), quo(am == 1)) 12 | 13 | quo <- set_env(quo((!! quo(cyl == 2)) | (!! quo(am == 1))), base_env()) 14 | expect_identical(any_exprs(cyl == 2, am == 1), quo) 15 | }) 16 | 17 | test_that("all_exprs() without expression returns an error", { 18 | expect_error( 19 | all_exprs(), 20 | "At least one expression must be given", 21 | fixed = TRUE 22 | ) 23 | }) 24 | -------------------------------------------------------------------------------- /man/make_tbl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tbl.r 3 | \name{make_tbl} 4 | \alias{make_tbl} 5 | \title{Create a "tbl" object} 6 | \usage{ 7 | make_tbl(subclass, ...) 8 | } 9 | \arguments{ 10 | \item{subclass}{name of subclass. "tbl" is an abstract base class, so you 11 | must supply this value. \code{tbl_} is automatically prepended to the 12 | class name} 13 | 14 | \item{...}{For \code{tbl()}, other fields used by class. For \code{as.tbl()}, 15 | other arguments passed to methods.} 16 | 17 | \item{object}{to test/coerce.} 18 | } 19 | \description{ 20 | \code{tbl()} is the standard constructor for tbls. \code{as.tbl()} coerces, 21 | and \code{is.tbl()} tests. 22 | } 23 | \examples{ 24 | as.tbl(mtcars) 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /R/na_if.R: -------------------------------------------------------------------------------- 1 | #' Convert values to NA 2 | #' 3 | #' This is a translation of the SQL command `NULL_IF`. It is useful 4 | #' if you want to convert an annoying value to `NA`. 5 | #' 6 | #' @param x Vector to modify 7 | #' @param y Value to replace with NA 8 | #' @return A modified version of `x` that replaces any values that 9 | #' are equal to `y` with NA. 10 | #' @seealso [coalesce()] to replace missing values with a specified 11 | #' value. 12 | #' @export 13 | #' @examples 14 | #' na_if(1:5, 5:1) 15 | #' 16 | #' x <- c(1, -1, 0, 10) 17 | #' 100 / x 18 | #' 100 / na_if(x, 0) 19 | #' 20 | #' y <- c("abc", "def", "", "ghi") 21 | #' na_if(y, "") 22 | na_if <- function(x, y) { 23 | check_length(y, x, fmt_args("y"), glue("same as {fmt_args(~x)}")) 24 | 25 | x[x == y] <- NA 26 | x 27 | } 28 | -------------------------------------------------------------------------------- /inst/include/dplyr/vector_class.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_vector_class_H 2 | #define dplyr_vector_class_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | inline std::string vector_class(); 8 | 9 | template <> 10 | inline std::string vector_class() { 11 | return "integer"; 12 | } 13 | template <> 14 | inline std::string vector_class() { 15 | return "numeric"; 16 | } 17 | template <> 18 | inline std::string vector_class() { 19 | return "character"; 20 | } 21 | template <> 22 | inline std::string vector_class() { 23 | return "logical"; 24 | } 25 | template <> 26 | inline std::string vector_class() { 27 | return "list"; 28 | } 29 | template <> 30 | inline std::string vector_class() { 31 | return "complex"; 32 | } 33 | 34 | 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inst/include/tools/collapse.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_collapse_H 2 | #define dplyr_collapse_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | const char* to_string_utf8(typename Rcpp::traits::storage_type::type from) { 8 | SEXP s = Rcpp::internal::r_coerce(from); 9 | return Rf_translateCharUTF8(s); 10 | } 11 | 12 | template 13 | std::string collapse_utf8(const Vector& x, const char* sep = ", ", const char* quote = "") { 14 | std::stringstream ss; 15 | int n = x.size(); 16 | if (n > 0) { 17 | ss << quote << to_string_utf8(x[0]) << quote; 18 | for (int i = 1; i < n; i++) { 19 | const char* st = to_string_utf8(x[i]); 20 | ss << sep << quote << st << quote; 21 | } 22 | } 23 | 24 | return ss.str(); 25 | } 26 | 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /man/grouped_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/grouped-df.r 3 | \name{grouped_df} 4 | \alias{grouped_df} 5 | \alias{is.grouped_df} 6 | \alias{is_grouped_df} 7 | \title{A grouped data frame.} 8 | \usage{ 9 | grouped_df(data, vars, drop = TRUE) 10 | 11 | is.grouped_df(x) 12 | 13 | is_grouped_df(x) 14 | } 15 | \arguments{ 16 | \item{data}{a tbl or data frame.} 17 | 18 | \item{vars}{a character vector or a list of \code{\link[=name]{name()}}} 19 | 20 | \item{drop}{if \code{TRUE} preserve all factor levels, even those without 21 | data.} 22 | } 23 | \description{ 24 | The easiest way to create a grouped data frame is to call the \code{group_by()} 25 | method on a data frame or tbl: this will take care of capturing 26 | the unevaluated expressions for you. 27 | } 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /inst/include/dplyr/HybridHandlerMap.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_HybridHandlerMap_H 2 | #define dplyr_dplyr_HybridHandlerMap_H 3 | 4 | #include 5 | #include 6 | 7 | typedef dplyr_hash_map HybridHandlerMap; 8 | 9 | void install_simple_handlers(HybridHandlerMap& handlers); 10 | void install_minmax_handlers(HybridHandlerMap& handlers); 11 | void install_count_handlers(HybridHandlerMap& handlers); 12 | void install_nth_handlers(HybridHandlerMap& handlers); 13 | void install_window_handlers(HybridHandlerMap& handlers); 14 | void install_offset_handlers(HybridHandlerMap& handlers); 15 | void install_in_handlers(HybridHandlerMap& handlers); 16 | void install_debug_handlers(HybridHandlerMap& handlers); 17 | 18 | bool hybridable(RObject arg); 19 | 20 | #endif // dplyr_dplyr_HybridHandlerMap_H 21 | -------------------------------------------------------------------------------- /inst/include/tools/hash.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_HASH_H 2 | #define dplyr_HASH_H 3 | 4 | #include 5 | 6 | #ifndef dplyr_hash_map 7 | #if defined(_WIN32) 8 | #define dplyr_hash_map RCPP_UNORDERED_MAP 9 | #else 10 | #include 11 | #define dplyr_hash_map boost::unordered_map 12 | #endif 13 | #endif // #ifndef dplyr_hash_map 14 | 15 | #ifndef dplyr_hash_set 16 | #if defined(_WIN32) 17 | #define dplyr_hash_set RCPP_UNORDERED_SET 18 | #else 19 | #include 20 | #define dplyr_hash_set boost::unordered_set 21 | #endif 22 | #endif // #ifndef dplyr_hash_set 23 | 24 | inline std::size_t hash_value(const Rcomplex& cx) { 25 | boost::hash hasher; 26 | size_t seed = hasher(cx.r); 27 | boost::hash_combine(seed, hasher(cx.i)); 28 | return seed; 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /tests/testthat/utf-8.R: -------------------------------------------------------------------------------- 1 | # UTF-8 tests that can't be run on Windows CRAN 2 | df <- data.frame(中文1 = 1:10, 中文2 = 1:10, eng = 1:10) 3 | df2 <- df %>% mutate(中文1 = 中文1 + 1) 4 | gdf2 <- df %>% group_by(eng) %>% mutate(中文1 = 中文1 + 1) 5 | 6 | expect_equal(strings_addresses(names(df)), strings_addresses(names(df2))) 7 | expect_equal(strings_addresses(names(df)), strings_addresses(names(gdf2))) 8 | 9 | df3 <- filter(df2, eng > 5) 10 | gdf3 <- filter(gdf2, eng > 5) 11 | expect_equal(strings_addresses(names(df)), strings_addresses(names(df3))) 12 | expect_equal(strings_addresses(names(df)), strings_addresses(names(gdf3))) 13 | 14 | df4 <- filter(df2, 中文1 > 5) 15 | gdf4 <- filter(gdf2, 中文1 > 5) 16 | expect_equal(strings_addresses(names(df)), strings_addresses(names(df4))) 17 | expect_equal(strings_addresses(names(df)), strings_addresses(names(gdf4))) 18 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please briefly describe your problem and what output you expect. If you have a question, please don't use this form, but instead ask on the mailing list or http://stackoverflow.com. 2 | 3 | Please include a minimal reprex. The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it. If you've never heard of a reprex before, start by reading , and follow the advice further down the page. Do NOT include session info unless it's explicitly asked for, or you've used `reprex::reprex(..., si = TRUE)` to hide it away. 4 | 5 | Delete these instructions once you have read them. 6 | 7 | --- 8 | 9 | Brief description of the problem 10 | 11 | ```r 12 | # insert reprex here 13 | ``` 14 | -------------------------------------------------------------------------------- /R/data-starwars.R: -------------------------------------------------------------------------------- 1 | #' Starwars characters 2 | #' 3 | #' This data comes from SWAPI, the Star Wars API, 4 | #' 5 | #' @format A tibble with 87 rows and 13 variables: 6 | #' \describe{ 7 | #' \item{name}{Name of the character} 8 | #' \item{height}{Height (cm)} 9 | #' \item{mass}{Weight (kg)} 10 | #' \item{hair_color,skin_color,eye_color}{Hair, skin, and eye colors} 11 | #' \item{birth_year}{Year born (BBY = Before Battle of Yavin)} 12 | #' \item{gender}{male, female, hermaphrodite, or none.} 13 | #' \item{homeworld}{Name of homeworld} 14 | #' \item{species}{Name of species} 15 | #' \item{films}{List of films the character appeared in} 16 | #' \item{vehicles}{List of vehicles the character has piloted} 17 | #' \item{starships}{List of starships the character has piloted} 18 | #' } 19 | #' @examples 20 | #' starwars 21 | "starwars" 22 | -------------------------------------------------------------------------------- /R/data-bands.R: -------------------------------------------------------------------------------- 1 | #' Band membership 2 | #' 3 | #' These data sets describe band members of the Beatles and Rolling Stones. They 4 | #' are toy data sets that can be displayed in their entirety on a slide (e.g. to 5 | #' demonstrate a join). 6 | #' 7 | #' `band_instruments` and `band_instruments2` contain the same data but use 8 | #' different column names for the first column of the data set. 9 | #' `band_instruments` uses `name`, which matches the name of the key column of 10 | #' `band_members`; `band_instruments2` uses `artist`, which does not. 11 | #' 12 | #' @format Each is a tibble with two variables and three observations 13 | #' @examples 14 | #' band_members 15 | #' band_instruments 16 | #' band_instruments2 17 | "band_members" 18 | 19 | #' @rdname band_members 20 | "band_instruments" 21 | 22 | #' @rdname band_members 23 | "band_instruments2" 24 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorSetEqual.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorSetEqual_H 2 | #define dplyr_VisitorSetEqual_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | class VisitorSetEqual { 8 | public: 9 | bool equal(int i, int j) const { 10 | const Class& obj = static_cast(*this); 11 | if (i == j) return true; 12 | int n = obj.size(); 13 | for (int k = 0; k < n; k++) 14 | if (! obj.get(k)->equal(i, j)) return false; 15 | return true; 16 | } 17 | 18 | bool equal_or_both_na(int i, int j) const { 19 | const Class& obj = static_cast(*this); 20 | if (i == j) return true; 21 | int n = obj.size(); 22 | for (int k = 0; k < n; k++) 23 | if (! obj.get(k)->equal_or_both_na(i, j)) return false; 24 | return true; 25 | } 26 | }; 27 | 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /man/na_if.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/na_if.R 3 | \name{na_if} 4 | \alias{na_if} 5 | \title{Convert values to NA} 6 | \usage{ 7 | na_if(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{Vector to modify} 11 | 12 | \item{y}{Value to replace with NA} 13 | } 14 | \value{ 15 | A modified version of \code{x} that replaces any values that 16 | are equal to \code{y} with NA. 17 | } 18 | \description{ 19 | This is a translation of the SQL command \code{NULL_IF}. It is useful 20 | if you want to convert an annoying value to \code{NA}. 21 | } 22 | \examples{ 23 | na_if(1:5, 5:1) 24 | 25 | x <- c(1, -1, 0, 10) 26 | 100 / x 27 | 100 / na_if(x, 0) 28 | 29 | y <- c("abc", "def", "", "ghi") 30 | na_if(y, "") 31 | } 32 | \seealso{ 33 | \code{\link[=coalesce]{coalesce()}} to replace missing values with a specified 34 | value. 35 | } 36 | -------------------------------------------------------------------------------- /tests/testthat/test-n_distinct.R: -------------------------------------------------------------------------------- 1 | context("n_distinct") 2 | 3 | test_that("count_distinct gives the correct results on iris", { 4 | expect_equal( 5 | sapply(iris, n_distinct), 6 | sapply(iris, function(.) length(unique(.))) 7 | ) 8 | }) 9 | 10 | df_var <- data.frame( 11 | l = c(T, F, F), 12 | i = c(1, 1, 2), 13 | d = Sys.Date() + c(1, 1, 2), 14 | f = factor(letters[c(1, 1, 2)]), 15 | n = c(1, 1, 2) + 0.5, 16 | t = Sys.time() + c(1, 1, 2), 17 | c = letters[c(1, 1, 2)], 18 | stringsAsFactors = FALSE 19 | ) 20 | test_that("count_distinct gives correct results for key types", { 21 | expect_equal( 22 | sapply(df_var, n_distinct), 23 | sapply(df_var, function(.) length(unique(.))) 24 | ) 25 | }) 26 | 27 | test_that("n_distinct treats NA correctly in the REALSXP case (#384)", { 28 | expect_equal(n_distinct(c(1.0, NA, NA)), 2) 29 | }) 30 | -------------------------------------------------------------------------------- /inst/include/dplyr/tbl_cpp.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_tools_tbl_cpp_H 2 | #define dplyr_tools_tbl_cpp_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | template 9 | inline void set_rownames(Df& data, int n) { 10 | data.attr("row.names") = 11 | Rcpp::IntegerVector::create(Rcpp::IntegerVector::get_na(), -n); 12 | } 13 | 14 | template 15 | inline Rcpp::CharacterVector classes_grouped() { 16 | return Rcpp::CharacterVector::create("grouped_df", "tbl_df", "tbl", "data.frame"); 17 | } 18 | 19 | template <> 20 | inline Rcpp::CharacterVector classes_grouped() { 21 | return Rcpp::CharacterVector::create("rowwise_df", "tbl_df", "tbl", "data.frame"); 22 | } 23 | 24 | inline Rcpp::CharacterVector classes_not_grouped() { 25 | return Rcpp::CharacterVector::create("tbl_df", "tbl", "data.frame"); 26 | } 27 | 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/VectorSliceVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_VectorSliceVisitor_H 2 | #define dplyr_Result_VectorSliceVisitor_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | template 9 | class VectorSliceVisitor { 10 | public: 11 | typedef typename Rcpp::traits::storage_type::type STORAGE; 12 | 13 | VectorSliceVisitor(const Vector* data_, const SlicingIndex& index_) : 14 | data(*data_), 15 | n(index_.size()), 16 | index(index_) 17 | {} 18 | 19 | inline STORAGE operator[](int i) const { 20 | return data[index[i]]; 21 | } 22 | 23 | inline int size() const { 24 | return n; 25 | } 26 | 27 | inline operator SEXP() const { 28 | return wrap_subset(data, index); 29 | } 30 | 31 | private: 32 | const Vector& data; 33 | int n; 34 | const SlicingIndex& index; 35 | }; 36 | 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /man/check_dbplyr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compat-dbplyr.R 3 | \name{check_dbplyr} 4 | \alias{check_dbplyr} 5 | \alias{wrap_dbplyr_obj} 6 | \title{dbplyr compatibility functions} 7 | \usage{ 8 | check_dbplyr() 9 | 10 | wrap_dbplyr_obj(obj_name) 11 | } 12 | \description{ 13 | In dplyr 0.7.0, a number of database and SQL functions moved from dplyr to 14 | dbplyr. The generic functions stayed in dplyr (since there is no easy way 15 | to conditionally import a generic from different packages), but many other 16 | SQL and database helper functions moved. If you have written a backend, 17 | these functions generate the code you need to work with both dplyr 0.5.0 18 | dplyr 0.7.0. 19 | } 20 | \examples{ 21 | if (requireNamespace("dbplyr", quietly = TRUE)) { 22 | wrap_dbplyr_obj("build_sql") 23 | wrap_dbplyr_obj("base_agg") 24 | } 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/src_local.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/src-local.r 3 | \name{src_local} 4 | \alias{src_local} 5 | \alias{src_df} 6 | \title{A local source.} 7 | \usage{ 8 | src_local(tbl, pkg = NULL, env = NULL) 9 | 10 | src_df(pkg = NULL, env = NULL) 11 | } 12 | \arguments{ 13 | \item{tbl}{name of the function used to generate \code{tbl} objects} 14 | 15 | \item{pkg, env}{Either the name of a package or an environment object in 16 | which to look for objects.} 17 | } 18 | \description{ 19 | This is mainly useful for testing, since makes it possible to refer to 20 | local and remote tables using exactly the same syntax. 21 | } 22 | \details{ 23 | Generally, \code{src_local()} should not be called directly, but instead 24 | one of the constructors should be used. 25 | } 26 | \examples{ 27 | if (require("Lahman")) { 28 | batting_df <- tbl(src_df("Lahman"), "Batting") 29 | } 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /man/as.table.tbl_cube.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tbl-cube.r 3 | \name{as.table.tbl_cube} 4 | \alias{as.table.tbl_cube} 5 | \alias{as.data.frame.tbl_cube} 6 | \alias{as_data_frame.tbl_cube} 7 | \title{Coerce a \code{tbl_cube} to other data structures} 8 | \usage{ 9 | \method{as.table}{tbl_cube}(x, ..., measure = 1L) 10 | 11 | \method{as.data.frame}{tbl_cube}(x, ...) 12 | 13 | \method{as_data_frame}{tbl_cube}(x, ...) 14 | } 15 | \arguments{ 16 | \item{x}{a \code{tbl_cube}} 17 | 18 | \item{...}{Passed on to individual methods; otherwise ignored.} 19 | 20 | \item{measure}{A measure name or index, default: the first measure} 21 | } 22 | \description{ 23 | Supports conversion to tables, data frames, tibbles. 24 | 25 | For a cube, the data frame returned by 26 | \code{\link[tibble:as_data_frame]{tibble::as_data_frame()}} resulting data frame contains the 27 | dimensions as character values (and not as factors). 28 | } 29 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorSetIndexSet.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorSetIndexSet_H 2 | #define dplyr_VisitorSetIndexSet_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace dplyr { 10 | 11 | template 12 | class VisitorSetIndexSet : public dplyr_hash_set, VisitorSetEqualPredicate > { 13 | private: 14 | typedef VisitorSetHasher Hasher; 15 | typedef VisitorSetEqualPredicate EqualPredicate; 16 | typedef dplyr_hash_set Base; 17 | 18 | public: 19 | VisitorSetIndexSet() : Base() {} 20 | 21 | VisitorSetIndexSet(VisitorSet& visitors_) : 22 | Base(1024, Hasher(&visitors_), EqualPredicate(&visitors_)) 23 | {} 24 | VisitorSetIndexSet(VisitorSet* visitors_) : 25 | Base(1024, Hasher(visitors_), EqualPredicate(visitors_)) 26 | {} 27 | }; 28 | 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/GroupedCallReducer.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_GroupedCallReducer_H 2 | #define dplyr_GroupedCallReducer_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace dplyr { 10 | 11 | template 12 | class GroupedCallReducer : public CallbackProcessor< GroupedCallReducer > { 13 | public: 14 | GroupedCallReducer(Rcpp::Call call, const Subsets& subsets, const Environment& env, const SymbolString& name_) : 15 | proxy(call, subsets, env), 16 | name(name_) 17 | { 18 | } 19 | 20 | virtual ~GroupedCallReducer() {}; 21 | 22 | inline SEXP process_chunk(const SlicingIndex& indices) { 23 | return proxy.get(indices); 24 | } 25 | 26 | const SymbolString& get_name() const { 27 | return name; 28 | } 29 | 30 | private: 31 | GroupedCallProxy proxy; 32 | const SymbolString name; 33 | }; 34 | 35 | } // namespace dplyr 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /man/starwars.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-starwars.R 3 | \docType{data} 4 | \name{starwars} 5 | \alias{starwars} 6 | \title{Starwars characters} 7 | \format{A tibble with 87 rows and 13 variables: 8 | \describe{ 9 | \item{name}{Name of the character} 10 | \item{height}{Height (cm)} 11 | \item{mass}{Weight (kg)} 12 | \item{hair_color,skin_color,eye_color}{Hair, skin, and eye colors} 13 | \item{birth_year}{Year born (BBY = Before Battle of Yavin)} 14 | \item{gender}{male, female, hermaphrodite, or none.} 15 | \item{homeworld}{Name of homeworld} 16 | \item{species}{Name of species} 17 | \item{films}{List of films the character appeared in} 18 | \item{vehicles}{List of vehicles the character has piloted} 19 | \item{starships}{List of starships the character has piloted} 20 | }} 21 | \usage{ 22 | starwars 23 | } 24 | \description{ 25 | This data comes from SWAPI, the Star Wars API, \url{http://swapi.co/} 26 | } 27 | \examples{ 28 | starwars 29 | } 30 | \keyword{datasets} 31 | -------------------------------------------------------------------------------- /tests/testthat/test-copying.R: -------------------------------------------------------------------------------- 1 | context("Copying") 2 | 3 | test_that("coercion doesn't copy vars", { 4 | mtcars2 <- tbl_df(mtcars) 5 | mtcars3 <- as.data.frame(mtcars2) 6 | 7 | expect_equal(location(mtcars2)$vars, location(mtcars)$vars) 8 | expect_equal(location(mtcars3)$vars, location(mtcars)$vars) 9 | }) 10 | 11 | test_that("grouping and ungrouping doesn't copy vars", { 12 | mtcars2 <- group_by(mtcars, cyl) 13 | mtcars3 <- ungroup(mtcars2) 14 | 15 | expect_equal(location(mtcars2)$vars, location(mtcars)$vars) 16 | expect_equal(location(mtcars3)$vars, location(mtcars)$vars) 17 | }) 18 | 19 | test_that("mutate doesn't copy vars", { 20 | mtcars2 <- tbl_df(mtcars) 21 | mtcars3 <- mutate(mtcars2, cyl2 = cyl * 2) 22 | 23 | expect_equal(location(mtcars3)$vars[1:11], location(mtcars2)$vars) 24 | }) 25 | 26 | test_that("select doesn't copy vars", { 27 | mtcars2 <- tbl_df(mtcars) 28 | mtcars3 <- select(mtcars2, carb:mpg) 29 | 30 | expect_equal(location(mtcars3)$vars[11:1], location(mtcars2)$vars) 31 | }) 32 | -------------------------------------------------------------------------------- /revdep/cran.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | We checked 893 reverse dependencies (821 from CRAN + 72 from BioConductor), comparing R CMD check results across CRAN and dev versions of this package. 4 | 5 | * We saw 8 new problems 6 | * We failed to check 3 packages 7 | 8 | Issues with CRAN packages are summarised below. 9 | 10 | ### New problems 11 | (This reports the first line of each new failure) 12 | 13 | * assertr 14 | checking tests ... 15 | 16 | * breathtestcore 17 | checking tests ... 18 | 19 | * desctable 20 | checking examples ... ERROR 21 | checking re-building of vignette outputs ... WARNING 22 | 23 | * GSODR 24 | checking tests ... 25 | 26 | * keyholder 27 | checking tests ... 28 | 29 | * mrgsolve 30 | checking examples ... ERROR 31 | 32 | * neuropsychology 33 | checking examples ... ERROR 34 | 35 | * sf 36 | checking examples ... ERROR 37 | 38 | ### Failed to check 39 | 40 | * cdcfluview (failed to install) 41 | * dataRetrieval (check timed out) 42 | * loon (failed to install) 43 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/In.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_In_H 2 | #define dplyr_Result_In_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace dplyr { 9 | 10 | template 11 | class In : public Mutater > { 12 | public: 13 | typedef typename Rcpp::Vector Vec; 14 | typedef typename Rcpp::traits::storage_type::type STORAGE; 15 | 16 | In(Vec data_, const Vec& table_) : 17 | data(data_), 18 | set(table_.begin(), table_.end()) 19 | {} 20 | 21 | void process_slice(LogicalVector& out, const SlicingIndex& index, const SlicingIndex& out_index) { 22 | int n = index.size(); 23 | for (int i = 0; i < n; i++) { 24 | STORAGE value = data[index[i]]; 25 | if (Vec::is_na(value)) { 26 | out[ out_index[i] ] = false; 27 | } else { 28 | out[ out_index[i] ] = set.count(value); 29 | } 30 | } 31 | } 32 | 33 | private: 34 | Vec data; 35 | dplyr_hash_set set; 36 | 37 | }; 38 | 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /man/rowwise.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rowwise.r 3 | \name{rowwise} 4 | \alias{rowwise} 5 | \title{Group input by rows} 6 | \usage{ 7 | rowwise(data) 8 | } 9 | \arguments{ 10 | \item{data}{Input data frame.} 11 | } 12 | \description{ 13 | \code{rowwise()} is used for the results of \code{\link[=do]{do()}} when you 14 | create list-variables. It is also useful to support arbitrary 15 | complex operations that need to be applied to each row. 16 | } 17 | \details{ 18 | Currently, rowwise grouping only works with data frames. Its 19 | main impact is to allow you to work with list-variables in 20 | \code{\link[=summarise]{summarise()}} and \code{\link[=mutate]{mutate()}} without having to 21 | use \code{[[1]]}. This makes \code{summarise()} on a rowwise tbl 22 | effectively equivalent to \code{\link[plyr:ldply]{plyr::ldply()}}. 23 | } 24 | \examples{ 25 | df <- expand.grid(x = 1:3, y = 3:1) 26 | df \%>\% rowwise() \%>\% do(i = seq(.$x, .$y)) 27 | .Last.value \%>\% summarise(n = length(i)) 28 | } 29 | -------------------------------------------------------------------------------- /tests/testthat/test-colwise-filter.R: -------------------------------------------------------------------------------- 1 | context("colwise filter") 2 | 3 | test_that("filter_if()", { 4 | expect_identical(nrow(filter_if(mtcars, is_integerish, all_vars(. > 1))), 0L) 5 | expect_identical(nrow(filter_if(mtcars, is_integerish, all_vars(. > 0))), 7L) 6 | }) 7 | 8 | test_that("filter_at()", { 9 | sepal_large <- filter_at(iris, vars(starts_with("Sepal")), all_vars(. > 4)) 10 | expect_equal(sepal_large$Sepal.Length, c(5.7, 5.2, 5.5)) 11 | }) 12 | 13 | test_that("filter_all()", { 14 | expect_identical(filter_all(mtcars, any_vars(. > 200))$disp, mtcars$disp[mtcars$disp > 200]) 15 | }) 16 | 17 | test_that("aborts on empty selection", { 18 | expect_error( 19 | filter_if(mtcars, is_character, all_vars(. > 0)), 20 | "`.predicate` has no matching columns", 21 | fixed = TRUE 22 | ) 23 | }) 24 | 25 | test_that("aborts when supplied funs()", { 26 | expect_error( 27 | filter_all(mtcars, funs(. > 0)), 28 | "`.vars_predicate` must be a call to `all_vars()` or `any_vars()`, not list", 29 | fixed = TRUE 30 | ) 31 | }) 32 | -------------------------------------------------------------------------------- /inst/include/dplyr/VectorVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VectorVisitor_H 2 | #define dplyr_VectorVisitor_H 3 | 4 | namespace dplyr { 5 | 6 | /** 7 | * Vector visitor base class, defines the interface 8 | */ 9 | class VectorVisitor { 10 | public: 11 | virtual ~VectorVisitor() {} 12 | 13 | /** hash the element of the visited vector at index i */ 14 | virtual size_t hash(int i) const = 0; 15 | 16 | /** are the elements at indices i and j equal */ 17 | virtual bool equal(int i, int j) const = 0; 18 | 19 | /** are the elements at indices i and j equal or both NA */ 20 | virtual bool equal_or_both_na(int i, int j) const = 0; 21 | 22 | /** is the i element less than the j element */ 23 | virtual bool less(int i, int j) const = 0; 24 | 25 | /** is the i element less than the j element */ 26 | virtual bool greater(int i, int j) const = 0; 27 | 28 | virtual int size() const = 0; 29 | 30 | virtual std::string get_r_type() const = 0; 31 | 32 | virtual bool is_na(int i) const = 0; 33 | }; 34 | 35 | } // namespace dplyr 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/ILazySubsets.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_ILazySubsets_H 2 | #define dplyr_ILazySubsets_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace dplyr { 9 | 10 | class ILazySubsets { 11 | protected: 12 | ILazySubsets() {} 13 | 14 | public: 15 | virtual ~ILazySubsets() {} 16 | 17 | virtual const SymbolVector get_variable_names() const = 0; 18 | virtual SEXP get_variable(const SymbolString& symbol) const = 0; 19 | virtual SEXP get(const SymbolString& symbol, const SlicingIndex& indices) const = 0; 20 | virtual bool is_summary(const SymbolString& symbol) const = 0; 21 | virtual bool has_variable(const SymbolString& symbol) const = 0; 22 | virtual void input(const SymbolString& symbol, SEXP x) = 0; 23 | virtual int size() const = 0; 24 | virtual int nrows() const = 0; 25 | 26 | public: 27 | bool has_non_summary_variable(const SymbolString& symbol) const { 28 | return has_variable(symbol) && !is_summary(symbol); 29 | } 30 | }; 31 | 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /tests/testthat/test-lazyeval-compat.R: -------------------------------------------------------------------------------- 1 | context("lazyeval compatibility") 2 | 3 | test_that("can select negatively (#2519)", { 4 | expect_identical(select_(mtcars, ~-cyl), mtcars[-2]) 5 | }) 6 | 7 | test_that("select yields proper names", { 8 | expect_identical(names(select_(mtcars, ~cyl:hp)), c("cyl", "disp", "hp")) 9 | }) 10 | 11 | test_that("lazydots are named and arrange() doesn't fail (it assumes empty names)", { 12 | dots <- compat_lazy_dots(list(), env(), "cyl") 13 | expect_identical(names(dots), "") 14 | expect_identical(arrange_(mtcars, "cyl"), arrange(mtcars, cyl)) 15 | }) 16 | 17 | test_that("mutate_each_() and summarise_each_() handle lazydots", { 18 | cyl_chr <- mutate_each_(mtcars, funs(as.character), "cyl")$cyl 19 | expect_identical(cyl_chr, as.character(mtcars$cyl)) 20 | 21 | cyl_mean <- summarise_each_(mtcars, funs(mean), "cyl")$cyl 22 | expect_equal(cyl_mean, mean(mtcars$cyl)) 23 | }) 24 | 25 | test_that("select_vars_() handles lazydots", { 26 | expect_identical(select_vars_(letters, c("a", "b")), set_names(c("a", "b"))) 27 | }) 28 | -------------------------------------------------------------------------------- /R/zzz.r: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname) { 2 | op <- options() 3 | op.dplyr <- list( 4 | dplyr.show_progress = TRUE 5 | ) 6 | toset <- !(names(op.dplyr) %in% names(op)) 7 | if (any(toset)) options(op.dplyr[toset]) 8 | 9 | invisible() 10 | } 11 | 12 | .onAttach <- function(libname, pkgname) { 13 | setHook(packageEvent("plyr", "attach"), function(...) { 14 | packageStartupMessage(rule()) 15 | packageStartupMessage("You have loaded plyr after dplyr - this is likely ", 16 | "to cause problems.\nIf you need functions from both plyr and dplyr, ", 17 | "please load plyr first, then dplyr:\nlibrary(plyr); library(dplyr)") 18 | packageStartupMessage(rule()) 19 | }) 20 | } 21 | 22 | .onDetach <- function(libpath) { 23 | setHook(packageEvent("plyr", "attach"), NULL, "replace") 24 | } 25 | 26 | when_attached <- function(pkg, action) { 27 | if (is_attached(pkg)) { 28 | action 29 | } else { 30 | setHook(packageEvent(pkg, "attach"), function(...) action) 31 | } 32 | } 33 | 34 | is_attached <- function(pkg) paste0("package:", pkg) %in% search() 35 | -------------------------------------------------------------------------------- /man/band_members.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-bands.R 3 | \docType{data} 4 | \name{band_members} 5 | \alias{band_members} 6 | \alias{band_instruments} 7 | \alias{band_instruments2} 8 | \title{Band membership} 9 | \format{Each is a tibble with two variables and three observations} 10 | \usage{ 11 | band_members 12 | 13 | band_instruments 14 | 15 | band_instruments2 16 | } 17 | \description{ 18 | These data sets describe band members of the Beatles and Rolling Stones. They 19 | are toy data sets that can be displayed in their entirety on a slide (e.g. to 20 | demonstrate a join). 21 | } 22 | \details{ 23 | \code{band_instruments} and \code{band_instruments2} contain the same data but use 24 | different column names for the first column of the data set. 25 | \code{band_instruments} uses \code{name}, which matches the name of the key column of 26 | \code{band_members}; \code{band_instruments2} uses \code{artist}, which does not. 27 | } 28 | \examples{ 29 | band_members 30 | band_instruments 31 | band_instruments2 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /src/init.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace Rcpp; 8 | using namespace dplyr; 9 | 10 | SEXP get_cache() { 11 | static SEXP cache = 0; 12 | if (!cache) { 13 | SEXP vec = PROTECT(Rf_allocVector(VECSXP, 2)); 14 | SEXP date_classes = PROTECT(Rf_mkString("Date")); 15 | SET_VECTOR_ELT(vec, 0, date_classes); 16 | CharacterVector time_classes = CharacterVector::create("POSIXct", "POSIXt"); 17 | SET_VECTOR_ELT(vec, 1, time_classes); 18 | UNPROTECT(2); 19 | R_PreserveObject(vec); 20 | cache = vec; 21 | } 22 | return cache; 23 | } 24 | 25 | // [[Rcpp::interfaces(cpp)]] 26 | // [[Rcpp::export]] 27 | SEXP get_date_classes() { 28 | return VECTOR_ELT(get_cache(), 0); 29 | } 30 | 31 | // [[Rcpp::interfaces(cpp)]] 32 | // [[Rcpp::export]] 33 | SEXP get_time_classes() { 34 | return VECTOR_ELT(get_cache(), 1); 35 | } 36 | 37 | // work around a problem (?) in Rcpp 38 | // [[Rcpp::interfaces(cpp)]] 39 | // [[Rcpp::export]] 40 | DataFrame build_index_cpp(DataFrame data); 41 | -------------------------------------------------------------------------------- /inst/include/tools/Call.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr__Call_h 2 | #define dplyr__Call_h 3 | 4 | namespace Rcpp { 5 | 6 | class Call { 7 | public: 8 | 9 | Call() : data(R_NilValue) {} 10 | 11 | Call(SEXP x) : data(x) { 12 | if (data != R_NilValue) R_PreserveObject(data); 13 | } 14 | 15 | ~Call() { 16 | if (data != R_NilValue) R_ReleaseObject(data); 17 | } 18 | 19 | Call(const Call& other) : data(other.data) { 20 | if (data != R_NilValue) R_PreserveObject(data); 21 | } 22 | 23 | Call& operator=(SEXP other) { 24 | if (other != data) { 25 | if (data != R_NilValue) R_ReleaseObject(data); 26 | data = other; 27 | if (data != R_NilValue) R_PreserveObject(data); 28 | } 29 | return *this; 30 | } 31 | 32 | inline SEXP eval(SEXP env) const { 33 | return Rcpp_eval(data, env); 34 | } 35 | 36 | inline operator SEXP() const { 37 | return data; 38 | } 39 | 40 | private: 41 | SEXP data; 42 | 43 | Call& operator=(const Call& other); 44 | // { 45 | // *this = other.data; 46 | // return *this; 47 | // } 48 | 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /man/setops.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sets.r 3 | \name{setops} 4 | \alias{setops} 5 | \alias{intersect} 6 | \alias{union} 7 | \alias{union_all} 8 | \alias{setdiff} 9 | \alias{setequal} 10 | \title{Set operations} 11 | \usage{ 12 | intersect(x, y, ...) 13 | 14 | union(x, y, ...) 15 | 16 | union_all(x, y, ...) 17 | 18 | setdiff(x, y, ...) 19 | 20 | setequal(x, y, ...) 21 | } 22 | \arguments{ 23 | \item{x, y}{objects to perform set function on (ignoring order)} 24 | 25 | \item{...}{other arguments passed on to methods} 26 | } 27 | \description{ 28 | These functions override the set functions provided in base to make them 29 | generic so that efficient versions for data frames and other tables can be 30 | provided. The default methods call the base versions. 31 | } 32 | \examples{ 33 | mtcars$model <- rownames(mtcars) 34 | first <- mtcars[1:20, ] 35 | second <- mtcars[10:32, ] 36 | 37 | intersect(first, second) 38 | union(first, second) 39 | setdiff(first, second) 40 | setdiff(second, first) 41 | 42 | union_all(first, second) 43 | setequal(mtcars, mtcars[32:1, ]) 44 | } 45 | -------------------------------------------------------------------------------- /R/dr.R: -------------------------------------------------------------------------------- 1 | Rcpp_version <- utils::packageVersion("Rcpp") 2 | R_version <- R.version.string 3 | 4 | #' Dr Dplyr checks your installation for common problems. 5 | #' 6 | #' Only run this if you are seeing problems, like random crashes. 7 | #' It's possible for `dr_dplyr` to return false positives, so there's no 8 | #' need to run if all is ok. 9 | #' 10 | #' @export 11 | #' @examples 12 | #' \dontrun{ 13 | #' dr_dplyr() 14 | #' } 15 | dr_dplyr <- function() { 16 | if (Rcpp_version != utils::packageVersion("Rcpp")) { 17 | warning( 18 | "Installed Rcpp (", utils::packageVersion("Rcpp"), ") different from ", 19 | "Rcpp used to build dplyr (", Rcpp_version, ").\n", 20 | "Please reinstall dplyr to avoid random crashes or undefined behavior.", 21 | call. = FALSE 22 | ) 23 | } 24 | 25 | if (R_version != R.version.string) { 26 | warning( 27 | "Installed R (", R.version.string, ") different from ", 28 | "R used to build dplyr (", R_version, ").\n", 29 | "Please reinstall dplyr to avoid random crashes or undefined behavior.", 30 | call. = FALSE 31 | ) 32 | } 33 | 34 | invisible(NULL) 35 | } 36 | -------------------------------------------------------------------------------- /tests/testthat/helper-astyle.R: -------------------------------------------------------------------------------- 1 | vcapply <- function(X, FUN, ..., USE.NAMES = TRUE) { 2 | vapply(X = X, FUN = FUN, FUN.VALUE = character(1L), ..., USE.NAMES = USE.NAMES) 3 | } 4 | 5 | astyle <- function(extra_args = character()) { 6 | astyle_cmd <- "astyle" 7 | if (Sys.which(astyle_cmd) == "") { 8 | skip("astyle not found") 9 | } 10 | 11 | astyle_args <- c( 12 | "-n", 13 | "--indent=spaces=2", 14 | "--unpad-paren", 15 | "--pad-header", 16 | "--pad-oper", 17 | "--min-conditional-indent=0", 18 | "--align-pointer=type", 19 | "--align-reference=type" 20 | ) 21 | 22 | src_path <- normalizePath(map_chr(c("../../src", "../../inst/include"), testthat::test_path)) 23 | src_files <- dir(src_path, "[.](?:cpp|h)$", recursive = TRUE, full.names = TRUE) 24 | astyle_files <- grep("(?:RcppExports[.](?:cpp|h)|static_assert[.]h)", src_files, value = TRUE, invert = TRUE) 25 | output <- system2(astyle_cmd, c(astyle_args, astyle_files, extra_args), stdout = TRUE, stderr = TRUE) 26 | unchanged <- grepl("^Unchanged", output) 27 | if (any(!unchanged)) { 28 | rlang::warn(paste(output[!unchanged], collapse = "\n")) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/rlang-export.c: -------------------------------------------------------------------------------- 1 | #define R_NO_REMAP 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #if (defined(R_VERSION) && R_VERSION < R_Version(3, 4, 0)) 8 | SEXP R_MakeExternalPtrFn(DL_FUNC p, SEXP tag, SEXP prot) { 9 | fn_ptr ptr; 10 | ptr.fn = p; 11 | return R_MakeExternalPtr(ptr.p, tag, prot); 12 | } 13 | DL_FUNC R_ExternalPtrAddrFn(SEXP s) { 14 | fn_ptr ptr; 15 | ptr.p = EXTPTR_PTR(s); 16 | return ptr.fn; 17 | } 18 | #endif 19 | 20 | SEXP rlang_namespace(const char* ns) { 21 | SEXP call = PROTECT(Rf_lang2(Rf_install("getNamespace"), PROTECT(Rf_mkString(ns)))); 22 | SEXP ns_env = Rf_eval(call, R_BaseEnv); 23 | UNPROTECT(2); 24 | return ns_env; 25 | } 26 | 27 | void rlang_register_pointer(const char* ns, const char* ptr_name, DL_FUNC fn) { 28 | SEXP ptr = PROTECT(R_MakeExternalPtrFn(fn, R_NilValue, R_NilValue)); 29 | 30 | SEXP ptr_obj = PROTECT(Rf_allocVector(VECSXP, 1)); 31 | SET_VECTOR_ELT(ptr_obj, 0, ptr); 32 | 33 | Rf_setAttrib(ptr_obj, R_ClassSymbol, Rf_mkString("fn_pointer")); 34 | 35 | Rf_defineVar(Rf_install(ptr_name), ptr_obj, PROTECT(rlang_namespace(ns))); 36 | UNPROTECT(3); 37 | } 38 | -------------------------------------------------------------------------------- /inst/include/dplyr/visitor_set/VisitorSetIndexMap.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_VisitorSetIndexMap_H 2 | #define dplyr_VisitorSetIndexMap_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace dplyr { 10 | 11 | template 12 | class VisitorSetIndexMap : 13 | public dplyr_hash_map, VisitorSetEqualPredicate > { 14 | private: 15 | typedef VisitorSetHasher Hasher; 16 | typedef VisitorSetEqualPredicate EqualPredicate; 17 | typedef typename dplyr_hash_map Base; 18 | 19 | public: 20 | VisitorSetIndexMap() : Base(), visitors(0) {} 21 | 22 | VisitorSetIndexMap(VisitorSet& visitors_) : 23 | Base(1024, Hasher(&visitors_), EqualPredicate(&visitors_)), 24 | visitors(&visitors_) 25 | {} 26 | 27 | VisitorSetIndexMap(VisitorSet* visitors_) : 28 | Base(1024, Hasher(visitors_), EqualPredicate(visitors_)), 29 | visitors(visitors_) 30 | {} 31 | 32 | VisitorSet* visitors; 33 | 34 | }; 35 | 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /tests/testthat/test-group-size.R: -------------------------------------------------------------------------------- 1 | context("Group sizes") 2 | 3 | test_that("ungrouped data has 1 group, with group size = nrow()", { 4 | df <- tibble(x = rep(1:3, each = 10), y = rep(1:6, each = 5)) 5 | 6 | expect_equal(n_groups(df), 1L) 7 | expect_equal(group_size(df), 30) 8 | }) 9 | 10 | test_that("rowwise data has one group for each group", { 11 | rw <- rowwise(mtcars) 12 | expect_equal(n_groups(rw), 32) 13 | expect_equal(group_size(rw), rep(1, 32)) 14 | }) 15 | 16 | test_that("group_size correct for grouped data", { 17 | df <- tibble(x = rep(1:3, each = 10), y = rep(1:6, each = 5)) %>% group_by(x) 18 | expect_equal(n_groups(df), 3L) 19 | expect_equal(group_size(df), rep(10, 3)) 20 | }) 21 | 22 | 23 | # For following tests, add an extra level that's not present in data 24 | test_that("n_groups drops zero-length groups", { 25 | df <- tibble(x = factor(1:3, levels = 1:4)) %>% group_by(x) 26 | expect_equal(n_groups(df), 3) 27 | }) 28 | 29 | test_that("summarise drops zero-length groups", { 30 | df <- tibble(x = factor(rep(1:3, each = 10))) 31 | 32 | out <- df %>% 33 | group_by(x) %>% 34 | summarise(n = n()) 35 | 36 | expect_equal(out$n, c(10L, 10L, 10L)) 37 | }) 38 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright © 2013-2015 RStudio and others. 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the “Software”), to deal in the Software without 9 | restriction, including without limitation the rights to use, 10 | copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | OTHER DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /R/data-nasa.r: -------------------------------------------------------------------------------- 1 | #' NASA spatio-temporal data 2 | #' 3 | #' This data comes from the ASA 2007 data expo, 4 | #' \url{http://stat-computing.org/dataexpo/2006/}. The data are geographic and 5 | #' atmospheric measures on a very coarse 24 by 24 grid covering Central 6 | #' America. The variables are: temperature (surface and air), ozone, 7 | #' air pressure, and cloud cover (low, mid, and high). All variables are 8 | #' monthly averages, with observations for Jan 1995 to Dec 2000. These data 9 | #' were obtained from the NASA Langley Research Center Atmospheric Sciences 10 | #' Data Center (with permission; see important copyright terms below). 11 | #' 12 | #' @section Dimensions: 13 | #' 14 | #' \itemize{ 15 | #' \item `lat`, `long`: latitude and longitude 16 | #' \item `year`, `month`: month and year 17 | #' } 18 | #' 19 | #' @section Measures: 20 | #' 21 | #' \itemize{ 22 | #' \item `cloudlow`, `cloudmed`, `cloudhigh`: cloud cover 23 | #' at three heights 24 | #' \item `ozone` 25 | #' \item `surftemp` and `temperature` 26 | #' \item `pressure` 27 | #' } 28 | #' @docType data 29 | #' @name nasa 30 | #' @usage nasa 31 | #' @format A [tbl_cube] with 41,472 observations. 32 | #' @examples 33 | #' nasa 34 | NULL 35 | -------------------------------------------------------------------------------- /inst/include/dplyr/DataFrameColumnVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_DataFrameColumnVisitors_H 2 | #define dplyr_DataFrameColumnVisitors_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | class DataFrameColumnVisitor : public VectorVisitor { 9 | public: 10 | DataFrameColumnVisitor(const DataFrame& data_) : data(data_), visitors(data) {} 11 | 12 | inline size_t hash(int i) const { 13 | return visitors.hash(i); 14 | } 15 | 16 | inline bool equal(int i, int j) const { 17 | return visitors.equal(i, j); 18 | } 19 | 20 | inline bool equal_or_both_na(int i, int j) const { 21 | return visitors.equal_or_both_na(i, j); 22 | } 23 | 24 | inline bool less(int i, int j) const { 25 | return visitors.less(i, j); 26 | } 27 | 28 | inline bool greater(int i, int j) const { 29 | return visitors.greater(i, j); 30 | } 31 | 32 | virtual int size() const { 33 | return visitors.nrows(); 34 | } 35 | 36 | virtual std::string get_r_type() const { 37 | return "data.frame"; 38 | } 39 | 40 | bool is_na(int) const { 41 | return false; 42 | } 43 | 44 | private: 45 | DataFrame data; 46 | DataFrameVisitors visitors; 47 | }; 48 | 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /tests/testthat/test-nth-value.R: -------------------------------------------------------------------------------- 1 | context("Nth value") 2 | 3 | test_that("nth works with lists", { 4 | x <- list(1, 2, 3) 5 | 6 | expect_equal(nth(x, 1), 1) 7 | expect_equal(nth(x, 4), NULL) 8 | expect_equal(nth(x, 4, default = 1), 1) 9 | }) 10 | 11 | test_that("negative values index from end", { 12 | x <- 1:5 13 | 14 | expect_equal(nth(x, -1), 5) 15 | expect_equal(nth(x, -3), 3) 16 | }) 17 | 18 | test_that("indexing past ends returns default value", { 19 | expect_equal(nth(1:4, 5), NA_integer_) 20 | expect_equal(nth(1:4, -5), NA_integer_) 21 | expect_equal(nth(1:4, -10), NA_integer_) 22 | }) 23 | 24 | test_that("first uses default value for 0 length vectors", { 25 | expect_equal(first(logical()), NA) 26 | expect_equal(first(integer()), NA_integer_) 27 | expect_equal(first(numeric()), NA_real_) 28 | expect_equal(first(character()), NA_character_) 29 | expect_equal(first(list()), NULL) 30 | }) 31 | 32 | test_that("firsts uses default value for 0 length augmented vectors", { 33 | fc <- factor("a")[0] 34 | dt <- Sys.Date() 35 | tm <- Sys.time() 36 | 37 | expect_equal(first(fc[0]), fc[NA]) 38 | expect_equal(first(dt[0]), dt[NA]) 39 | expect_equal(first(tm[0]), tm[NA]) 40 | }) 41 | -------------------------------------------------------------------------------- /src/group_by.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | using namespace Rcpp; 11 | using namespace dplyr; 12 | 13 | // [[Rcpp::export]] 14 | DataFrame grouped_df_impl(DataFrame data, SymbolVector symbols, bool drop) { 15 | assert_all_white_list(data); 16 | DataFrame copy(shallow_copy(data)); 17 | set_vars(copy, symbols); 18 | copy.attr("drop") = drop; 19 | if (!symbols.size()) 20 | stop("no variables to group by"); 21 | return build_index_cpp(copy); 22 | } 23 | 24 | // [[Rcpp::export]] 25 | DataFrame as_regular_df(DataFrame df) { 26 | DataFrame copy(shallow_copy(df)); 27 | SET_ATTRIB(copy, strip_group_attributes(df)); 28 | SET_OBJECT(copy, OBJECT(df)); 29 | set_class(copy, CharacterVector::create("data.frame")); 30 | return copy; 31 | } 32 | 33 | // [[Rcpp::export]] 34 | DataFrame ungroup_grouped_df(DataFrame df) { 35 | DataFrame copy(shallow_copy(df)); 36 | SET_ATTRIB(copy, strip_group_attributes(df)); 37 | return copy; 38 | } 39 | 40 | // [[Rcpp::export]] 41 | SEXP test_grouped_df(DataFrame data) { 42 | return GroupedDataFrame(data).data(); 43 | } 44 | -------------------------------------------------------------------------------- /R/data-storms.R: -------------------------------------------------------------------------------- 1 | #' Storm tracks data 2 | #' 3 | #' This data is a subset of the NOAA Atlantic hurricane database best track 4 | #' data, \url{http://www.nhc.noaa.gov/data/#hurdat}. The data includes the 5 | #' positions and attributes of 198 tropical storms, measured every six hours 6 | #' during the lifetime of a storm. 7 | #' 8 | #' @format A tibble with 10,010 observations and 13 variables: 9 | #' \describe{ 10 | #' \item{name}{Storm Name} 11 | #' \item{year,month,day}{Date of report} 12 | #' \item{hour}{Hour of report (in UTC)} 13 | #' \item{lat,long}{Location of storm center} 14 | #' \item{status}{Storm classification (Tropical Depression, Tropical Storm, 15 | #' or Hurricane)} 16 | #' \item{category}{Saffir-Simpson storm category (estimated from wind speed. 17 | #' -1 = Tropical Depression, 0 = Tropical Storm)} 18 | #' \item{wind}{storm's maximum sustained wind speed (in knots)} 19 | #' \item{pressure}{Air pressure at the storm's center (in millibars)} 20 | #' \item{ts_diameter}{Diameter of the area experiencing tropical storm strength winds (34 knots or above)} 21 | #' \item{hu_diameter}{Diameter of the area experiencing hurricane strength winds (64 knots or above)} 22 | #' } 23 | #' @examples 24 | #' storms 25 | "storms" 26 | -------------------------------------------------------------------------------- /man/copy_to.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/copy-to.r 3 | \name{copy_to} 4 | \alias{copy_to} 5 | \title{Copy a local data frame to a remote src} 6 | \usage{ 7 | copy_to(dest, df, name = deparse(substitute(df)), overwrite = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{dest}{remote data source} 11 | 12 | \item{df}{local data frame} 13 | 14 | \item{name}{name for new remote table.} 15 | 16 | \item{overwrite}{If \code{TRUE}, will overwrite an existing table with 17 | name \code{name}. If \code{FALSE}, will throw an error if \code{name} already 18 | exists.} 19 | 20 | \item{...}{other parameters passed to methods.} 21 | } 22 | \value{ 23 | a \code{tbl} object in the remote source 24 | } 25 | \description{ 26 | This function uploads a local data frame into a remote data source, creating 27 | the table definition as needed. Wherever possible, the new object will be 28 | temporary, limited to the current connection to the source. 29 | } 30 | \examples{ 31 | \dontrun{ 32 | iris2 <- dbplyr::src_memdb() \%>\% copy_to(iris, overwrite = TRUE) 33 | iris2 34 | } 35 | } 36 | \seealso{ 37 | \code{\link[=collect]{collect()}} for the opposite action; downloading remote data into 38 | a local dbl. 39 | } 40 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/CumMax.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_CumMax_H 2 | #define dplyr_Result_CumMax_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | // version for REALSXP 9 | template 10 | class CumMax : public Mutater > { 11 | public: 12 | typedef typename Rcpp::traits::storage_type::type STORAGE; 13 | 14 | CumMax(SEXP data_) : data(data_) {} 15 | 16 | void process_slice(Vector& out, const SlicingIndex& index, const SlicingIndex& out_index) { 17 | int n = index.size(); 18 | STORAGE value = data[index[0]]; 19 | out[out_index[0]] = value; 20 | if (NumericVector::is_na(value)) { 21 | for (int i = 1; i < n; i++) { 22 | out[out_index[i]] = value; 23 | } 24 | return; 25 | } 26 | 27 | for (int i = 1; i < n; i++) { 28 | STORAGE current = data[index[i]]; 29 | if (Rcpp::traits::is_na(current)) { 30 | for (int j = i; j < n; j++) { 31 | out[out_index[j]] = current; 32 | } 33 | return; 34 | } 35 | if (current > value) value = current; 36 | out[out_index[i]] = value; 37 | } 38 | } 39 | 40 | Vector data; 41 | }; 42 | 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/CumMin.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_CumMin_H 2 | #define dplyr_Result_CumMin_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | // version for REALSXP 9 | template 10 | class CumMin : public Mutater > { 11 | public: 12 | typedef typename Rcpp::traits::storage_type::type STORAGE; 13 | 14 | CumMin(SEXP data_) : data(data_) {} 15 | 16 | void process_slice(Vector& out, const SlicingIndex& index, const SlicingIndex& out_index) { 17 | int n = index.size(); 18 | STORAGE value = data[index[0]]; 19 | out[out_index[0]] = value; 20 | if (NumericVector::is_na(value)) { 21 | for (int i = 1; i < n; i++) { 22 | out[out_index[i]] = value; 23 | } 24 | return; 25 | } 26 | 27 | for (int i = 1; i < n; i++) { 28 | STORAGE current = data[index[i]]; 29 | if (Rcpp::traits::is_na(current)) { 30 | for (int j = i; j < n; j++) { 31 | out[out_index[j]] = current; 32 | } 33 | return; 34 | } 35 | if (current < value) value = current; 36 | out[out_index[i]] = value; 37 | } 38 | } 39 | 40 | Vector data; 41 | }; 42 | 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /man/order_by.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/order-by.R 3 | \name{order_by} 4 | \alias{order_by} 5 | \title{A helper function for ordering window function output} 6 | \usage{ 7 | order_by(order_by, call) 8 | } 9 | \arguments{ 10 | \item{order_by}{a vector to order_by} 11 | 12 | \item{call}{a function call to a window function, where the first argument 13 | is the vector being operated on} 14 | } 15 | \description{ 16 | This function makes it possible to control the ordering of window functions 17 | in R that don't have a specific ordering parameter. When translated to SQL 18 | it will modify the order clause of the OVER function. 19 | } 20 | \details{ 21 | This function works by changing the \code{call} to instead call 22 | \code{\link[=with_order]{with_order()}} with the appropriate arguments. 23 | } 24 | \examples{ 25 | order_by(10:1, cumsum(1:10)) 26 | x <- 10:1 27 | y <- 1:10 28 | order_by(x, cumsum(y)) 29 | 30 | df <- data.frame(year = 2000:2005, value = (0:5) ^ 2) 31 | scrambled <- df[sample(nrow(df)), ] 32 | 33 | wrong <- mutate(scrambled, running = cumsum(value)) 34 | arrange(wrong, year) 35 | 36 | right <- mutate(scrambled, running = order_by(year, cumsum(value))) 37 | arrange(right, year) 38 | } 39 | -------------------------------------------------------------------------------- /tests/testthat/test-group-indices.R: -------------------------------------------------------------------------------- 1 | context("Group indices") 2 | 3 | test_that("group_indices from ungrouped or grouped gives same result", { 4 | res1 <- group_indices(mtcars, cyl, vs, am) 5 | res2 <- mtcars %>% group_by(cyl, vs, am) %>% group_indices() 6 | expect_equal(res1, res2) 7 | }) 8 | 9 | test_that("group_indices handles the case where no variable is given (#867)", { 10 | res <- group_indices(mtcars) 11 | expect_true(all(res == 1L)) 12 | }) 13 | 14 | test_that("group_indices handles grouped data and no arguments", { 15 | res1 <- mtcars %>% group_by(cyl) %>% group_indices() 16 | res2 <- mtcars %>% group_indices(cyl) 17 | expect_equal(res1, res2) 18 | }) 19 | 20 | test_that("group_indices can be used in mutate (#2160)", { 21 | res1 <- mtcars %>% mutate(., group_idx = group_indices(., cyl)) 22 | res2 <- mtcars %>% mutate(group_idx = as.integer(factor(cyl))) 23 | expect_equal(res1, res2) 24 | }) 25 | 26 | test_that("group indices are updated correctly for joined grouped data frames (#2330)", { 27 | d1 <- data.frame(x = 1:2, y = 1:2) %>% group_by(x, y) 28 | expect_equal(group_indices(d1), d1$x) 29 | 30 | d2 <- expand.grid(x = 1:2, y = 1:2) 31 | res <- inner_join(d1, d2, by = "x") 32 | expect_equal(group_indices(res), res$x) 33 | }) 34 | -------------------------------------------------------------------------------- /man/funs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funs.R 3 | \name{funs} 4 | \alias{funs} 5 | \title{Create a list of functions calls.} 6 | \usage{ 7 | funs(..., .args = list()) 8 | } 9 | \arguments{ 10 | \item{...}{A list of functions specified by: 11 | \itemize{ 12 | \item Their name, \code{"mean"} 13 | \item The function itself, \code{mean} 14 | \item A call to the function with \code{.} as a dummy argument, 15 | \code{mean(., na.rm = TRUE)} 16 | } 17 | 18 | These arguments are automatically \link[rlang:quo]{quoted}. They 19 | support \link[rlang:quasiquotation]{unquoting} and splicing. See 20 | \code{vignette("programming")} for an introduction to these concepts.} 21 | 22 | \item{.args, args}{A named list of additional arguments to be added 23 | to all function calls.} 24 | } 25 | \description{ 26 | \code{funs()} provides a flexible way to generate a named list of 27 | functions for input to other functions like \code{\link[=summarise_at]{summarise_at()}}. 28 | } 29 | \examples{ 30 | funs(mean, "mean", mean(., na.rm = TRUE)) 31 | 32 | # Override default names 33 | funs(m1 = mean, m2 = "mean", m3 = mean(., na.rm = TRUE)) 34 | 35 | # If you have function names in a vector, use funs_ 36 | fs <- c("min", "max") 37 | funs_(fs) 38 | } 39 | -------------------------------------------------------------------------------- /inst/include/dplyr/dplyr.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_dplyr_dplyr_H 2 | #define dplyr_dplyr_dplyr_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #endif // #ifndef dplyr_dplyr_dplyr_H 38 | -------------------------------------------------------------------------------- /man/pull.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pull.R 3 | \name{pull} 4 | \alias{pull} 5 | \title{Pull out a single variable} 6 | \usage{ 7 | pull(.data, var = -1) 8 | } 9 | \arguments{ 10 | \item{.data}{A table of data} 11 | 12 | \item{var}{A variable specified as: 13 | \itemize{ 14 | \item a literal variable name 15 | \item a positive integer, giving the position counting from the left 16 | \item a negative integer, giving the position counting from the right. 17 | } 18 | 19 | The default returns the last column (on the assumption that's the 20 | column you've created most recently). 21 | 22 | This argument is taken by expression and supports 23 | \link[rlang:quasiquotation]{quasiquotation} (you can unquote column 24 | names and column positions).} 25 | } 26 | \description{ 27 | This works like \code{[[} for local data frames, and automatically collects 28 | before indexing for remote data tables. 29 | } 30 | \examples{ 31 | mtcars \%>\% pull(-1) 32 | mtcars \%>\% pull(1) 33 | mtcars \%>\% pull(cyl) 34 | 35 | # Also works for remote sources 36 | if (requireNamespace("dbplyr", quietly = TRUE)) { 37 | df <- dbplyr::memdb_frame(x = 1:10, y = 10:1, .name = "pull-ex") 38 | df \%>\% 39 | mutate(z = x * y) \%>\% 40 | pull() 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Release summary 2 | 3 | This is a minor bugfix release in response to errors with ASAN, UBSAN, and Fedora+clang builds on CRAN. We now were able to finally replicate the problems we were seeing on CRAN in a Docker container, our minimal fix resolves these problems. 4 | 5 | ## Test environments 6 | 7 | * local OS X install, R 3.4.1 8 | * ubuntu 12.04 (on travis-ci), R 3.4.1, R-oldrel, R-devel. 9 | * win-builder (devel) 10 | 11 | ## R CMD check results 12 | 13 | 0 ERRORs | 0 WARNINGs | 2 NOTEs 14 | 15 | * 6 days since last update 16 | 17 | The UB errors seem important to fix now. 18 | 19 | * checking installed package size ... NOTE 20 | 21 | This is all compiled code in the libs/ directory. 22 | 23 | ## Reverse dependencies 24 | 25 | We checked 804 reverse dependencies (730 from CRAN + 74 from BioConductor) by running R CMD check twice, once with the CRAN version installed, and once with this version installed. We saw 2 new problems. We failed to check 4 packages. Issues are summarised below. 26 | 27 | ### New problems 28 | 29 | Most likely web API problems: 30 | 31 | * banR 32 | * FedData 33 | 34 | ### Failed to check 35 | 36 | * eyetrackingR (check timed out) 37 | * hypothesisr (check timed out) 38 | * loon (failed to install) 39 | * MonetDBLite (check timed out) 40 | -------------------------------------------------------------------------------- /man/as.tbl_cube.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tbl-cube.r 3 | \name{as.tbl_cube} 4 | \alias{as.tbl_cube} 5 | \alias{as.tbl_cube.array} 6 | \alias{as.tbl_cube.table} 7 | \alias{as.tbl_cube.matrix} 8 | \alias{as.tbl_cube.data.frame} 9 | \title{Coerce an existing data structure into a \code{tbl_cube}} 10 | \usage{ 11 | as.tbl_cube(x, ...) 12 | 13 | \method{as.tbl_cube}{array}(x, dim_names = names(dimnames(x)), 14 | met_name = deparse(substitute(x)), ...) 15 | 16 | \method{as.tbl_cube}{table}(x, dim_names = names(dimnames(x)), 17 | met_name = "Freq", ...) 18 | 19 | \method{as.tbl_cube}{matrix}(x, dim_names = names(dimnames(x)), 20 | met_name = deparse(substitute(x)), ...) 21 | 22 | \method{as.tbl_cube}{data.frame}(x, dim_names = NULL, 23 | met_name = guess_met(x), ...) 24 | } 25 | \arguments{ 26 | \item{x}{an object to convert. Built in methods will convert arrays, 27 | tables and data frames.} 28 | 29 | \item{...}{Passed on to individual methods; otherwise ignored.} 30 | 31 | \item{dim_names}{names of the dimensions. Defaults to the names of} 32 | 33 | \item{met_name}{a string to use as the name for the measure 34 | the \code{\link[=dimnames]{dimnames()}}.} 35 | } 36 | \description{ 37 | Coerce an existing data structure into a \code{tbl_cube} 38 | } 39 | -------------------------------------------------------------------------------- /inst/include/dplyr/BoolResult.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_tools_BoolResult_H 2 | #define dplyr_tools_BoolResult_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | class BoolResult { 9 | public: 10 | BoolResult(bool result_) : result(result_) {} 11 | BoolResult(bool result_, const CharacterVector& msg) : result(result_), message(msg) {} 12 | 13 | inline operator SEXP() const { 14 | LogicalVector res = LogicalVector::create(result); 15 | res.attr("comment") = message; 16 | set_class(res, "BoolResult"); 17 | return res; 18 | } 19 | 20 | inline operator bool() const { 21 | return result; 22 | } 23 | 24 | inline std::string why_not() const { 25 | R_xlen_t n = message.length(); 26 | if (n == 0) 27 | return ""; 28 | 29 | if (n == 1) 30 | return std::string(message[0]); 31 | 32 | std::stringstream ss; 33 | ss << "\n"; 34 | for (int i = 0; i < n; ++i) { 35 | ss << "- " << std::string(message[i]) << "\n"; 36 | } 37 | 38 | return ss.str(); 39 | } 40 | 41 | private: 42 | bool result; 43 | CharacterVector message; 44 | }; 45 | 46 | inline BoolResult no_because(const CharacterVector& msg) { 47 | return BoolResult(false, msg); 48 | } 49 | 50 | inline BoolResult yes() { 51 | return true; 52 | } 53 | 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | $("#sidebar").stick_in_parent({ 3 | offset_top: $("#sidebar").offset().top 4 | }); 5 | $('body').scrollspy({ 6 | target: '#sidebar' 7 | }); 8 | 9 | var cur_path = paths(location.pathname); 10 | $("#navbar ul li a").each(function(index, value) { 11 | if (value.text == "Home") 12 | return; 13 | if (value.getAttribute("href") === "#") 14 | return; 15 | 16 | var path = paths(value.pathname); 17 | if (is_prefix(cur_path, path)) { 18 | // Add class to parent
  • , and enclosing
  • if in dropdown 19 | var menu_anchor = $(value); 20 | menu_anchor.parent().addClass("active"); 21 | menu_anchor.closest("li.dropdown").addClass("active"); 22 | } 23 | }); 24 | 25 | }); 26 | 27 | 28 | 29 | function paths(pathname) { 30 | var pieces = pathname.split("/"); 31 | pieces.shift(); // always starts with / 32 | 33 | var end = pieces[pieces.length - 1]; 34 | if (end === "index.html" || end === "") 35 | pieces.pop(); 36 | return(pieces); 37 | } 38 | 39 | function is_prefix(needle, haystack) { 40 | if (needle.length > haystack.lengh) 41 | return(false); 42 | 43 | for (var i = 0; i < haystack.length; i++) { 44 | if (needle[i] != haystack[i]) 45 | return(false); 46 | } 47 | 48 | return(true); 49 | } 50 | -------------------------------------------------------------------------------- /inst/include/tools/pointer_vector.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_tools_pointer_vector_H 2 | #define dplyr_tools_pointer_vector_H 3 | 4 | namespace dplyr { 5 | 6 | template 7 | class pointer_vector { 8 | public: 9 | 10 | typedef typename std::vector Vector; 11 | typedef typename Vector::reference reference; 12 | typedef typename Vector::const_reference const_reference; 13 | typedef typename Vector::size_type size_type; 14 | typedef typename Vector::value_type value_type; 15 | typedef typename Vector::iterator iterator; 16 | 17 | pointer_vector() : data() {} 18 | pointer_vector(size_type n) : data(n) {} 19 | inline ~pointer_vector() { 20 | typedef typename Vector::size_type size_type; 21 | size_type n = data.size(); 22 | iterator it = data.end(); 23 | --it; 24 | for (size_type i = 0; i < n; --it, i++) delete *it; 25 | } 26 | 27 | inline reference operator[](size_type i) { 28 | return data[i]; 29 | } 30 | inline const_reference operator[](size_type i) const { 31 | return data[i]; 32 | } 33 | inline void push_back(const value_type& value) { 34 | data.push_back(value); 35 | } 36 | inline size_type size() const { 37 | return data.size(); 38 | } 39 | 40 | private: 41 | Vector data; 42 | pointer_vector(const pointer_vector&); 43 | }; 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /tests/testthat/test-rank.R: -------------------------------------------------------------------------------- 1 | context("rank") 2 | 3 | ntile_h <- function(x, n) { 4 | tibble(x = x) %>% 5 | mutate(y = ntile(x, n)) %>% 6 | pull(y) 7 | } 8 | 9 | ntile_h_dplyr <- function(x, n) { 10 | tibble(x = x) %>% 11 | mutate(y = dplyr::ntile(x, n)) %>% 12 | pull(y) 13 | } 14 | test_that("ntile ignores number of NAs", { 15 | x <- c(1:3, NA, NA, NA) 16 | 17 | expect_equal(ntile(x, 3), x) 18 | expect_equal(ntile_h(x, 3), x) 19 | 20 | x1 <- c(1L, 1L, 1L, NA, NA, NA) 21 | expect_equal(ntile(x, 1), x1) 22 | expect_equal(ntile_h(x, 1), x1) 23 | }) 24 | 25 | test_that("ntile always returns an integer", { 26 | expect_equal(ntile(numeric(), 3), integer()) 27 | expect_equal(ntile_h(numeric(), 3), integer()) 28 | 29 | expect_equal(ntile(NA, 3), NA_integer_) 30 | expect_equal(ntile_h(NA, 3), NA_integer_) 31 | }) 32 | 33 | test_that("ntile handles character vectors consistently", { 34 | charvec_sort_test <- function() { 35 | x1 <- c("[", "]", NA, "B", "y", "a", "Z") 36 | x2 <- c("a", "b", "C") 37 | 38 | expect_equal(ntile_h(x1, 3), ntile_h_dplyr(x1, 3)) 39 | expect_equal(ntile_h(x2, 2), ntile_h_dplyr(x2, 2)) 40 | } 41 | 42 | # Test against both the local, and the C locale for collation 43 | charvec_sort_test() 44 | withr::with_collate("C", charvec_sort_test()) 45 | }) 46 | -------------------------------------------------------------------------------- /man/coalesce.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coalesce.R 3 | \name{coalesce} 4 | \alias{coalesce} 5 | \title{Find first non-missing element} 6 | \usage{ 7 | coalesce(...) 8 | } 9 | \arguments{ 10 | \item{...}{Vectors. All inputs should either be length 1, or the 11 | same length as the first argument. 12 | 13 | These dots support \link[rlang:tidy-dots]{tidy dots} features.} 14 | } 15 | \value{ 16 | A vector the same length as the first \code{...} argument with 17 | missing values replaced by the first non-missing value. 18 | } 19 | \description{ 20 | Given a set of vectors, \code{coalesce()} finds the first non-missing value 21 | at each position. This is inspired by the SQL \code{COALESCE} function 22 | which does the same thing for \code{NULL}s. 23 | } 24 | \examples{ 25 | # Use a single value to replace all missing values 26 | x <- sample(c(1:5, NA, NA, NA)) 27 | coalesce(x, 0L) 28 | 29 | # Or match together a complete vector from missing pieces 30 | y <- c(1, 2, NA, NA, 5) 31 | z <- c(NA, NA, 3, 4, 5) 32 | coalesce(y, z) 33 | 34 | # Supply lists by splicing them into dots: 35 | vecs <- list( 36 | c(1, 2, NA, NA, 5), 37 | c(NA, NA, 3, 4, 5) 38 | ) 39 | coalesce(!!! vecs) 40 | } 41 | \seealso{ 42 | \code{\link[=na_if]{na_if()}} to replace specified values with a \code{NA}. 43 | } 44 | -------------------------------------------------------------------------------- /man/select_vars.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reexport-tidyselect.R 3 | \name{select_vars} 4 | \alias{select_vars} 5 | \alias{rename_vars} 6 | \alias{select_var} 7 | \alias{current_vars} 8 | \title{Select variables} 9 | \usage{ 10 | select_vars(vars, ..., include = chr(), exclude = chr()) 11 | 12 | rename_vars(vars, ..., strict = TRUE) 13 | 14 | select_var(vars, var = -1) 15 | 16 | current_vars(...) 17 | } 18 | \arguments{ 19 | \item{vars}{A character vector of existing column names.} 20 | 21 | \item{...}{Expressions to compute.} 22 | 23 | \item{include, exclude}{Character vector of column names to always 24 | include/exclude.} 25 | 26 | \item{strict}{If \code{TRUE}, will throw an error if you attempt to 27 | rename a variable that doesn't exist.} 28 | 29 | \item{var}{A variable specified as in the same argument of 30 | \code{\link[tidyselect:vars_pull]{tidyselect::vars_pull()}}.} 31 | } 32 | \description{ 33 | \strong{Retired}: These functions now live in the tidyselect package as 34 | \code{\link[tidyselect:vars_select]{tidyselect::vars_select()}}, \code{\link[tidyselect:vars_rename]{tidyselect::vars_rename()}} and 35 | \code{\link[tidyselect:vars_pull]{tidyselect::vars_pull()}}. These dplyr aliases are soft-deprecated 36 | and will be deprecated sometimes in the future. 37 | } 38 | -------------------------------------------------------------------------------- /man/tidyeval.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-tidy-eval.R 3 | \name{tidyeval} 4 | \alias{tidyeval} 5 | \alias{quo} 6 | \alias{quos} 7 | \alias{enquo} 8 | \alias{enquos} 9 | \alias{quo_name} 10 | \alias{sym} 11 | \alias{ensym} 12 | \alias{syms} 13 | \alias{ensyms} 14 | \alias{expr} 15 | \alias{exprs} 16 | \alias{enexpr} 17 | \alias{enexprs} 18 | \alias{.data} 19 | \title{Tidy eval helpers} 20 | \description{ 21 | \itemize{ 22 | \item \code{\link[rlang]{sym}()} creates a symbol from a string and 23 | \code{\link[rlang]{syms}()} creates a list of symbols from a 24 | character vector. 25 | \item \code{\link[rlang]{expr}()} and \code{\link[rlang]{quo}()} quote 26 | one expression. \code{quo()} wraps the quoted expression in a quosure. 27 | 28 | The plural variants \code{\link[rlang]{exprs}()} and 29 | \code{\link[rlang]{quos}()} return a list of quoted expressions or 30 | quosures. 31 | \item \code{\link[rlang]{enexpr}()} and \code{\link[rlang]{enquo}()} 32 | capture the expression supplied as argument by the user of the 33 | current function (\code{enquo()} wraps this expression in a quosure). 34 | 35 | \code{\link[rlang]{enexprs}()} and \code{\link[rlang]{enquos}()} 36 | capture multiple expressions supplied as arguments, including 37 | \code{...}. 38 | } 39 | } 40 | \keyword{internal} 41 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/all.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_all_H 2 | #define dplyr_Result_all_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /man/nasa.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-nasa.r 3 | \docType{data} 4 | \name{nasa} 5 | \alias{nasa} 6 | \title{NASA spatio-temporal data} 7 | \format{A \link{tbl_cube} with 41,472 observations.} 8 | \usage{ 9 | nasa 10 | } 11 | \description{ 12 | This data comes from the ASA 2007 data expo, 13 | \url{http://stat-computing.org/dataexpo/2006/}. The data are geographic and 14 | atmospheric measures on a very coarse 24 by 24 grid covering Central 15 | America. The variables are: temperature (surface and air), ozone, 16 | air pressure, and cloud cover (low, mid, and high). All variables are 17 | monthly averages, with observations for Jan 1995 to Dec 2000. These data 18 | were obtained from the NASA Langley Research Center Atmospheric Sciences 19 | Data Center (with permission; see important copyright terms below). 20 | } 21 | \section{Dimensions}{ 22 | 23 | 24 | \itemize{ 25 | \item \code{lat}, \code{long}: latitude and longitude 26 | \item \code{year}, \code{month}: month and year 27 | } 28 | } 29 | 30 | \section{Measures}{ 31 | 32 | 33 | \itemize{ 34 | \item \code{cloudlow}, \code{cloudmed}, \code{cloudhigh}: cloud cover 35 | at three heights 36 | \item \code{ozone} 37 | \item \code{surftemp} and \code{temperature} 38 | \item \code{pressure} 39 | } 40 | } 41 | 42 | \examples{ 43 | nasa 44 | } 45 | -------------------------------------------------------------------------------- /man/all_vars.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/colwise.R 3 | \name{all_vars} 4 | \alias{all_vars} 5 | \alias{any_vars} 6 | \title{Apply predicate to all variables} 7 | \usage{ 8 | all_vars(expr) 9 | 10 | any_vars(expr) 11 | } 12 | \arguments{ 13 | \item{expr}{A predicate expression. This variable supports 14 | \link[rlang:quasiquotation]{unquoting} and will be evaluated in the 15 | context of the data frame. It should return a logical vector. 16 | 17 | This argument is automatically \link[rlang:quo]{quoted} and later 18 | \link[rlang:eval_tidy]{evaluated} in the context of the data 19 | frame. It supports \link[rlang:quasiquotation]{unquoting}. See 20 | \code{vignette("programming")} for an introduction to these concepts.} 21 | } 22 | \description{ 23 | These quoting functions signal to scoped filtering verbs 24 | (e.g. \code{\link[=filter_if]{filter_if()}} or \code{\link[=filter_all]{filter_all()}}) that a predicate expression 25 | should be applied to all relevant variables. The \code{all_vars()} 26 | variant takes the intersection of the predicate expressions with 27 | \code{&} while the \code{any_vars()} variant takes the union with \code{|}. 28 | } 29 | \seealso{ 30 | \code{\link[=funs]{funs()}} and \code{\link[=vars]{vars()}} for other quoting functions that you 31 | can use with scoped verbs. 32 | } 33 | -------------------------------------------------------------------------------- /man/vars.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/colwise.R 3 | \name{vars} 4 | \alias{vars} 5 | \title{Select variables} 6 | \usage{ 7 | vars(...) 8 | } 9 | \arguments{ 10 | \item{...}{Variables to include/exclude in mutate/summarise. You 11 | can use same specifications as in \code{\link[=select]{select()}}. If missing, 12 | defaults to all non-grouping variables. 13 | 14 | These arguments are automatically \link[rlang:quo]{quoted} and later 15 | \link[rlang:eval_tidy]{evaluated} in the context of the data 16 | frame. They support \link[rlang:quasiquotation]{unquoting}. See 17 | \code{vignette("programming")} for an introduction to these concepts.} 18 | } 19 | \description{ 20 | This helper is intended to provide equivalent semantics to 21 | \code{\link[=select]{select()}}. It is used for instance in scoped summarising and 22 | mutating verbs (\code{\link[=mutate_at]{mutate_at()}} and \code{\link[=summarise_at]{summarise_at()}}). 23 | } 24 | \details{ 25 | Note that verbs accepting a \code{vars()} specification also accept an 26 | \link[rlang:is_integerish]{integerish} vector of positions or a 27 | character vector of column names. 28 | } 29 | \seealso{ 30 | \code{\link[=funs]{funs()}}, \code{\link[=all_vars]{all_vars()}} and \code{\link[=any_vars]{any_vars()}} for other quoting 31 | functions that you can use with scoped verbs. 32 | } 33 | -------------------------------------------------------------------------------- /man/lead-lag.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lead-lag.R 3 | \name{lead-lag} 4 | \alias{lead-lag} 5 | \alias{lead} 6 | \alias{lag} 7 | \title{Lead and lag.} 8 | \usage{ 9 | lead(x, n = 1L, default = NA, order_by = NULL, ...) 10 | 11 | lag(x, n = 1L, default = NA, order_by = NULL, ...) 12 | } 13 | \arguments{ 14 | \item{x}{a vector of values} 15 | 16 | \item{n}{a positive integer of length 1, giving the number of positions to 17 | lead or lag by} 18 | 19 | \item{default}{value used for non-existent rows. Defaults to \code{NA}.} 20 | 21 | \item{order_by}{override the default ordering to use another vector} 22 | 23 | \item{...}{Needed for compatibility with lag generic.} 24 | } 25 | \description{ 26 | Find the "next" or "previous" values in a vector. Useful for comparing values 27 | ahead of or behind the current values. 28 | } 29 | \examples{ 30 | lead(1:10, 1) 31 | lead(1:10, 2) 32 | 33 | lag(1:10, 1) 34 | lead(1:10, 1) 35 | 36 | x <- runif(5) 37 | cbind(ahead = lead(x), x, behind = lag(x)) 38 | 39 | # Use order_by if data not already ordered 40 | df <- data.frame(year = 2000:2005, value = (0:5) ^ 2) 41 | scrambled <- df[sample(nrow(df)), ] 42 | 43 | wrong <- mutate(scrambled, prev = lag(value)) 44 | arrange(wrong, year) 45 | 46 | right <- mutate(scrambled, prev = lag(value, order_by = year)) 47 | arrange(right, year) 48 | } 49 | -------------------------------------------------------------------------------- /man/storms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-storms.R 3 | \docType{data} 4 | \name{storms} 5 | \alias{storms} 6 | \title{Storm tracks data} 7 | \format{A tibble with 10,010 observations and 13 variables: 8 | \describe{ 9 | \item{name}{Storm Name} 10 | \item{year,month,day}{Date of report} 11 | \item{hour}{Hour of report (in UTC)} 12 | \item{lat,long}{Location of storm center} 13 | \item{status}{Storm classification (Tropical Depression, Tropical Storm, 14 | or Hurricane)} 15 | \item{category}{Saffir-Simpson storm category (estimated from wind speed. 16 | -1 = Tropical Depression, 0 = Tropical Storm)} 17 | \item{wind}{storm's maximum sustained wind speed (in knots)} 18 | \item{pressure}{Air pressure at the storm's center (in millibars)} 19 | \item{ts_diameter}{Diameter of the area experiencing tropical storm strength winds (34 knots or above)} 20 | \item{hu_diameter}{Diameter of the area experiencing hurricane strength winds (64 knots or above)} 21 | }} 22 | \usage{ 23 | storms 24 | } 25 | \description{ 26 | This data is a subset of the NOAA Atlantic hurricane database best track 27 | data, \url{http://www.nhc.noaa.gov/data/#hurdat}. The data includes the 28 | positions and attributes of 198 tropical storms, measured every six hours 29 | during the lifetime of a storm. 30 | } 31 | \examples{ 32 | storms 33 | } 34 | \keyword{datasets} 35 | -------------------------------------------------------------------------------- /inst/include/dplyr/NamedListAccumulator.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_NamedListAccumulator_H 2 | #define dplyr_NamedListAccumulator_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace dplyr { 9 | 10 | template 11 | class NamedListAccumulator { 12 | private: 13 | SymbolMap symbol_map; 14 | std::vector data; // owns the results 15 | 16 | public: 17 | NamedListAccumulator() {} 18 | 19 | inline void set(const SymbolString& name, RObject x) { 20 | if (! Rcpp::traits::same_type::value) 21 | check_supported_type(x, name); 22 | 23 | SymbolMapIndex index = symbol_map.insert(name); 24 | if (index.origin == NEW) { 25 | data.push_back(x); 26 | } else { 27 | data[ index.pos ] = x; 28 | } 29 | 30 | } 31 | 32 | inline void rm(const SymbolString& name) { 33 | SymbolMapIndex index = symbol_map.rm(name); 34 | if (index.origin != NEW) { 35 | data.erase(data.begin() + index.pos); 36 | } 37 | } 38 | 39 | inline operator List() const { 40 | List out = wrap(data); 41 | out.names() = symbol_map.get_names(); 42 | return out; 43 | } 44 | 45 | inline size_t size() const { 46 | return data.size(); 47 | } 48 | 49 | inline const SymbolVector names() const { 50 | return symbol_map.get_names(); 51 | } 52 | 53 | }; 54 | 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/Var.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_Var_H 2 | #define dplyr_Result_Var_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | namespace internal { 9 | 10 | inline double square(double x) { 11 | return x * x; 12 | } 13 | 14 | } 15 | 16 | template 17 | class Var : public Processor > { 18 | public: 19 | typedef Processor > Base; 20 | typedef typename Rcpp::traits::storage_type::type STORAGE; 21 | 22 | Var(SEXP x) : 23 | Base(x), 24 | data_ptr(Rcpp::internal::r_vector_start(x)) 25 | {} 26 | ~Var() {} 27 | 28 | inline double process_chunk(const SlicingIndex& indices) { 29 | int n = indices.size(); 30 | if (n <= 1) return NA_REAL; 31 | double m = internal::Mean_internal::process(data_ptr, indices); 32 | 33 | if (!R_FINITE(m)) return m; 34 | 35 | double sum = 0.0; 36 | int count = 0; 37 | for (int i = 0; i < n; i++) { 38 | STORAGE current = data_ptr[indices[i]]; 39 | if (NA_RM && Rcpp::Vector::is_na(current)) continue; 40 | sum += internal::square(current - m); 41 | count++; 42 | } 43 | if (count <= 1) return NA_REAL; 44 | return sum / (count - 1); 45 | } 46 | 47 | private: 48 | STORAGE* data_ptr; 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /revdep/drake-base.R: -------------------------------------------------------------------------------- 1 | library(drake) 2 | library(tidyverse) 3 | library(glue) 4 | 5 | options(repos = revdepcheck:::get_repos(TRUE)) 6 | 7 | get_this_pkg <- function() { 8 | desc::desc_get("Package") %>% unname() 9 | } 10 | 11 | get_base_pkgs <- function() { 12 | rownames(installed.packages(priority = "base")) 13 | } 14 | 15 | flatten <- . %>% unname() %>% unlist() %>% unique() 16 | 17 | retry <- function(code, N = 1) { 18 | quo <- rlang::enquo(code) 19 | 20 | for (i in seq_len(N)) { 21 | ret <- tryCatch(rlang::eval_tidy(quo), error = identity) 22 | if (!inherits(ret, "error")) return(ret) 23 | Sys.sleep(runif(1) * 2) 24 | } 25 | 26 | stop(ret) 27 | } 28 | 29 | get_plan_deps <- function() { 30 | plan_deps <- drake_plan( 31 | available = available.packages(), 32 | this_pkg = get_this_pkg(), 33 | revdeps = tools::package_dependencies(this_pkg, available, 'most', reverse = TRUE) %>% flatten(), 34 | first_level_deps = tools::package_dependencies(revdeps, available, 'most'), 35 | all_level_deps = tools::package_dependencies(first_level_deps %>% flatten(), available, recursive = TRUE), 36 | base_pkgs = get_base_pkgs(), 37 | deps = c(revdeps, first_level_deps, all_level_deps) %>% flatten() %>% tools::package_dependencies(recursive = TRUE) %>% .[!(names(.) %in% base_pkgs)], 38 | strings_in_dots = "literals" 39 | ) 40 | 41 | plan_deps 42 | } 43 | -------------------------------------------------------------------------------- /R/utils-tidy-eval.R: -------------------------------------------------------------------------------- 1 | #' Tidy eval helpers 2 | #' 3 | #' @description 4 | #' 5 | #' * \code{\link[rlang]{sym}()} creates a symbol from a string and 6 | #' \code{\link[rlang]{syms}()} creates a list of symbols from a 7 | #' character vector. 8 | #' 9 | #' * \code{\link[rlang]{expr}()} and \code{\link[rlang]{quo}()} quote 10 | #' one expression. `quo()` wraps the quoted expression in a quosure. 11 | #' 12 | #' The plural variants \code{\link[rlang]{exprs}()} and 13 | #' \code{\link[rlang]{quos}()} return a list of quoted expressions or 14 | #' quosures. 15 | #' 16 | #' * \code{\link[rlang]{enexpr}()} and \code{\link[rlang]{enquo}()} 17 | #' capture the expression supplied as argument by the user of the 18 | #' current function (`enquo()` wraps this expression in a quosure). 19 | #' 20 | #' \code{\link[rlang]{enexprs}()} and \code{\link[rlang]{enquos}()} 21 | #' capture multiple expressions supplied as arguments, including 22 | #' `...`. 23 | #' 24 | #' @md 25 | #' @name tidyeval 26 | #' @keywords internal 27 | #' @aliases quo quos enquo enquos quo_name 28 | #' sym ensym syms ensyms 29 | #' expr exprs enexpr enexprs 30 | #' .data 31 | #' @export quo quos enquo enquos quo_name 32 | #' @export sym ensym syms ensyms 33 | #' @export expr exprs enexpr enexprs 34 | #' @export .data 35 | NULL 36 | -------------------------------------------------------------------------------- /inst/include/dplyr/DataFrameVisitors.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_DataFrameVisitors_H 2 | #define dplyr_DataFrameVisitors_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace dplyr { 12 | 13 | class DataFrameVisitors : 14 | public VisitorSetEqual, 15 | public VisitorSetHash, 16 | public VisitorSetLess, 17 | public VisitorSetGreater { 18 | 19 | private: 20 | 21 | const Rcpp::DataFrame& data; 22 | pointer_vector visitors; 23 | SymbolVector visitor_names; 24 | int nvisitors; 25 | 26 | public: 27 | typedef VectorVisitor visitor_type; 28 | 29 | DataFrameVisitors(const DataFrame& data_); 30 | 31 | DataFrameVisitors(const DataFrame& data_, const SymbolVector& names); 32 | 33 | inline int size() const { 34 | return nvisitors; 35 | } 36 | inline VectorVisitor* get(int k) const { 37 | return visitors[k]; 38 | } 39 | 40 | const SymbolString name(int k) const { 41 | return visitor_names[k]; 42 | } 43 | 44 | inline int nrows() const { 45 | return data.nrows(); 46 | } 47 | 48 | private: 49 | 50 | void structure(List& x, int nrows, CharacterVector classes) const; 51 | 52 | }; 53 | 54 | } // namespace dplyr 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/CumSum.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_CumSum_H 2 | #define dplyr_Result_CumSum_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | // REALSXP version 9 | template 10 | class CumSum : public Mutater > { 11 | public: 12 | CumSum(SEXP data_) : data(data_) {} 13 | 14 | void process_slice(Vector& out, const SlicingIndex& index, const SlicingIndex& out_index) { 15 | double value = 0.0; 16 | int n = index.size(); 17 | for (int i = 0; i < n; i++) { 18 | value += data[index[i]]; 19 | out[out_index[i]] = value; 20 | } 21 | } 22 | 23 | Vector data; 24 | }; 25 | 26 | // INTSXP version 27 | template <> 28 | class CumSum : public Mutater > { 29 | public: 30 | CumSum(SEXP data_) : data(data_) {} 31 | 32 | void process_slice(IntegerVector& out, const SlicingIndex& index, const SlicingIndex& out_index) { 33 | int value = 0; 34 | int n = index.size(); 35 | for (int i = 0; i < n; i++) { 36 | int current = data[index[i]]; 37 | if (IntegerVector::is_na(current)) { 38 | for (int j = i; j < n; j++) { 39 | out[ out_index[j] ] = NA_INTEGER; 40 | } 41 | return; 42 | } 43 | value += current; 44 | out[out_index[i]] = value; 45 | } 46 | } 47 | 48 | IntegerVector data; 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/hybrid_in.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | using namespace Rcpp; 11 | using namespace dplyr; 12 | 13 | Result* in_prototype(SEXP call, const ILazySubsets& subsets, int) { 14 | SEXP lhs = maybe_rhs(CADR(call)); 15 | SEXP rhs = maybe_rhs(CADDR(call)); 16 | 17 | // if lhs is not a symbol, let R handle it 18 | if (TYPEOF(lhs) != SYMSXP) return 0; 19 | 20 | SymbolString name = SymbolString(Symbol(lhs)); 21 | 22 | // if the lhs is not in the data, let R handle it 23 | if (!subsets.has_variable(name)) return 0; 24 | 25 | SEXP v = subsets.get_variable(name); 26 | 27 | // if the type of the data is not the same as the type of rhs, 28 | // including if it needs evaluation, let R handle it 29 | if (TYPEOF(v) != TYPEOF(rhs)) return 0; 30 | 31 | // otherwise use hybrid version 32 | switch (TYPEOF(v)) { 33 | case LGLSXP: 34 | return new In(v, rhs); 35 | case INTSXP: 36 | return new In(v, rhs); 37 | case REALSXP: 38 | return new In(v, rhs); 39 | case STRSXP: 40 | return new In(v, rhs); 41 | default: 42 | break; 43 | } 44 | 45 | // type not handled 46 | return 0; 47 | 48 | } 49 | 50 | void install_in_handlers(HybridHandlerMap& handlers) { 51 | handlers[ Rf_install("%in%") ] = in_prototype; 52 | } 53 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | # Default configuration for use with tic package 3 | # Usually you shouldn't need to change the first part of the file 4 | 5 | # DO NOT CHANGE THE CODE BELOW 6 | before_install: R -q -e 'install.packages(c("remotes", "curl")); remotes::install_github("ropenscilabs/tic"); tic::prepare_all_stages(); tic::before_install()' 7 | install: R -q -e 'tic::install()' 8 | after_install: R -q -e 'tic::after_install()' 9 | before_script: R -q -e 'tic::before_script()' 10 | script: R -q -e 'tic::script()' 11 | after_success: R -q -e 'tic::after_success()' 12 | after_failure: R -q -e 'tic::after_failure()' 13 | before_deploy: R -q -e 'tic::before_deploy()' 14 | deploy: 15 | provider: script 16 | script: R -q -e 'tic::deploy()' 17 | on: 18 | all_branches: true 19 | after_deploy: R -q -e 'tic::after_deploy()' 20 | after_script: R -q -e 'tic::after_script()' 21 | # DO NOT CHANGE THE CODE ABOVE 22 | 23 | # Custom parts: 24 | 25 | # Header 26 | language: r 27 | sudo: false 28 | dist: trusty 29 | cache: packages 30 | latex: false 31 | 32 | matrix: 33 | include: 34 | - r: oldrel 35 | - r: release 36 | env: 37 | - BUILD_PKGDOWN: true 38 | - r: devel 39 | 40 | #env 41 | env: 42 | global: 43 | - _R_CHECK_FORCE_SUGGESTS_=false 44 | - MAKEFLAGS="-j 2" 45 | - TRAVIS_CXXFLAGS="-Wall -Wextra -pedantic -Werror" 46 | 47 | #services 48 | services: 49 | -------------------------------------------------------------------------------- /inst/include/tools/ShrinkableVector.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_ShrinkableVector_H 2 | #define dplyr_ShrinkableVector_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Rcpp { 8 | 9 | template 10 | class ShrinkableVector { 11 | public: 12 | typedef typename Rcpp::traits::storage_type::type STORAGE; 13 | 14 | ShrinkableVector(int n, SEXP origin) : 15 | data(no_init(n)), max_size(n), start(internal::r_vector_start(data)), gp(LEVELS(data)) 16 | { 17 | copy_most_attributes(data, origin); 18 | SET_DPLYR_SHRINKABLE_VECTOR((SEXP)data); 19 | } 20 | 21 | inline void resize(int n) { 22 | SETLENGTH(data, n); 23 | } 24 | 25 | inline operator SEXP() const { 26 | return data; 27 | } 28 | 29 | inline void borrow(const SlicingIndex& indices, STORAGE* begin) { 30 | int n = indices.size(); 31 | for (int i = 0; i < n; i++) { 32 | start[i] = begin[indices[i]]; 33 | } 34 | SETLENGTH(data, n); 35 | } 36 | 37 | ~ShrinkableVector() { 38 | // restore the initial length so that R can reclaim the memory 39 | SETLENGTH(data, max_size); 40 | UNSET_DPLYR_SHRINKABLE_VECTOR((SEXP)data); 41 | } 42 | 43 | private: 44 | Rcpp::Vector data; 45 | int max_size; 46 | STORAGE* start; 47 | unsigned short gp; 48 | 49 | }; 50 | 51 | inline bool is_ShrinkableVector(SEXP x) { 52 | return IS_DPLYR_SHRINKABLE_VECTOR(x); 53 | } 54 | 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE the "init" and "install" sections below 2 | 3 | # Download script file from GitHub 4 | init: 5 | ps: | 6 | $ErrorActionPreference = "Stop" 7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 8 | Import-Module '..\appveyor-tool.ps1' 9 | 10 | install: 11 | ps: Bootstrap 12 | 13 | # Adapt as necessary starting from here 14 | 15 | environment: 16 | global: 17 | WARNINGS_ARE_ERRORS: 1 18 | GITHUB_PAT: 19 | secure: SAjXHKPAFPipSOE/6giubmF50pmgGtSFxyhe88E7RDv+q4PucnkyRK7Rs+/a7Vo0 20 | 21 | matrix: 22 | - R_VERSION: devel 23 | R_ARCH: x64 24 | GCC_PATH: mingw_64 25 | 26 | - R_VERSION: patched 27 | GCC_PATH: mingw_32 28 | 29 | build_script: 30 | - travis-tool.sh install_github r-pkgs/remotes@303db43 31 | - travis-tool.sh install_github tidyverse/dbplyr 32 | - travis-tool.sh install_deps 33 | 34 | test_script: 35 | - travis-tool.sh run_tests 36 | 37 | on_failure: 38 | - 7z a failure.zip *.Rcheck\* 39 | - appveyor PushArtifact failure.zip 40 | 41 | artifacts: 42 | - path: '*.Rcheck\**\*.log' 43 | name: Logs 44 | 45 | - path: '*.Rcheck\**\*.out' 46 | name: Logs 47 | 48 | - path: '*.Rcheck\**\*.fail' 49 | name: Logs 50 | 51 | - path: '*.Rcheck\**\*.Rout' 52 | name: Logs 53 | 54 | - path: '\*_*.tar.gz' 55 | name: Bits 56 | 57 | - path: '\*_*.zip' 58 | name: Bits 59 | -------------------------------------------------------------------------------- /man/progress_estimated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/progress.R 3 | \name{progress_estimated} 4 | \alias{progress_estimated} 5 | \title{Progress bar with estimated time.} 6 | \usage{ 7 | progress_estimated(n, min_time = 0) 8 | } 9 | \arguments{ 10 | \item{n}{Total number of items} 11 | 12 | \item{min_time}{Progress bar will wait until at least \code{min_time} 13 | seconds have elapsed before displaying any results.} 14 | } 15 | \value{ 16 | A ref class with methods \code{tick()}, \code{print()}, 17 | \code{pause()}, and \code{stop()}. 18 | } 19 | \description{ 20 | This reference class represents a text progress bar displayed estimated 21 | time remaining. When finished, it displays the total duration. The 22 | automatic progress bar can be disabled by setting option 23 | \code{dplyr.show_progress} to \code{FALSE}. 24 | } 25 | \examples{ 26 | p <- progress_estimated(3) 27 | p$tick() 28 | p$tick() 29 | p$tick() 30 | 31 | p <- progress_estimated(3) 32 | for (i in 1:3) p$pause(0.1)$tick()$print() 33 | 34 | p <- progress_estimated(3) 35 | p$tick()$print()$ 36 | pause(1)$stop() 37 | 38 | # If min_time is set, progress bar not shown until that many 39 | # seconds have elapsed 40 | p <- progress_estimated(3, min_time = 3) 41 | for (i in 1:3) p$pause(0.1)$tick()$print() 42 | 43 | \dontrun{ 44 | p <- progress_estimated(10, min_time = 3) 45 | for (i in 1:10) p$pause(0.5)$tick()$print() 46 | } 47 | } 48 | \keyword{internal} 49 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http://contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /R/colwise-arrange.R: -------------------------------------------------------------------------------- 1 | #' Arrange rows by a selection of variables 2 | #' 3 | #' These [scoped] variants of [arrange()] sort a data frame by a 4 | #' selection of variables. Like [arrange()], you can modify the 5 | #' variables before ordering with [funs()]. 6 | #' 7 | #' @inheritParams scoped 8 | #' @export 9 | #' @examples 10 | #' df <- as_tibble(mtcars) 11 | #' df 12 | #' arrange_all(df) 13 | #' 14 | #' # You can supply a function that will be applied before taking the 15 | #' # ordering of the variables. The variables of the sorted tibble 16 | #' # keep their original values. 17 | #' arrange_all(df, desc) 18 | #' arrange_all(df, funs(desc(.))) 19 | arrange_all <- function(.tbl, .funs = list(), ...) { 20 | funs <- manip_all(.tbl, .funs, enquo(.funs), caller_env(), ...) 21 | if (!length(funs)) { 22 | funs <- syms(tbl_vars(.tbl)) 23 | } 24 | arrange(.tbl, !!! funs) 25 | } 26 | #' @rdname arrange_all 27 | #' @export 28 | arrange_at <- function(.tbl, .vars, .funs = list(), ...) { 29 | funs <- manip_at(.tbl, .vars, .funs, enquo(.funs), caller_env(), ...) 30 | if (!length(funs)) { 31 | funs <- tbl_at_syms(.tbl, .vars) 32 | } 33 | arrange(.tbl, !!! funs) 34 | } 35 | #' @rdname arrange_all 36 | #' @export 37 | arrange_if <- function(.tbl, .predicate, .funs = list(), ...) { 38 | funs <- manip_if(.tbl, .predicate, .funs, enquo(.funs), caller_env(), ...) 39 | if (!length(funs)) { 40 | funs <- tbl_if_syms(.tbl, .predicate) 41 | } 42 | arrange(.tbl, !!! funs) 43 | } 44 | -------------------------------------------------------------------------------- /R/pull.R: -------------------------------------------------------------------------------- 1 | #' Pull out a single variable 2 | #' 3 | #' This works like `[[` for local data frames, and automatically collects 4 | #' before indexing for remote data tables. 5 | #' 6 | #' @param .data A table of data 7 | #' @inheritParams tidyselect::vars_pull 8 | #' @export 9 | #' @examples 10 | #' mtcars %>% pull(-1) 11 | #' mtcars %>% pull(1) 12 | #' mtcars %>% pull(cyl) 13 | #' 14 | #' # Also works for remote sources 15 | #' if (requireNamespace("dbplyr", quietly = TRUE)) { 16 | #' df <- dbplyr::memdb_frame(x = 1:10, y = 10:1, .name = "pull-ex") 17 | #' df %>% 18 | #' mutate(z = x * y) %>% 19 | #' pull() 20 | #' } 21 | #' 22 | pull <- function(.data, var = -1) { 23 | UseMethod("pull") 24 | } 25 | #' @export 26 | pull.data.frame <- function(.data, var = -1) { 27 | var <- tidyselect::vars_pull(names(.data), !! enquo(var)) 28 | .data[[var]] 29 | } 30 | 31 | # FIXME: remove this once dbplyr uses vars_pull() 32 | find_var <- function(expr, vars) { 33 | var_env <- set_names(as.list(seq_along(vars)), vars) 34 | var <- eval_tidy(expr, var_env) 35 | 36 | if (!is.numeric(var) || length(var) != 1) { 37 | bad_args("var", "must evaluate to a single number") 38 | } 39 | 40 | var <- as.integer(var) 41 | n <- length(vars) 42 | 43 | if (is.na(var) || abs(var) > n || var == 0L) { 44 | bad_args("var", "must be a value between {-n} and {n} (excluding zero), not {var}") 45 | } 46 | 47 | if (var < 0) { 48 | var <- var + n + 1 49 | } 50 | 51 | vars[[var]] 52 | } 53 | -------------------------------------------------------------------------------- /revdep/email.md: -------------------------------------------------------------------------------- 1 | Hi, 2 | 3 | This is an automated email to let you know about the release of {{{ my_package }}}, which will be submitted to CRAN in the near future (on {{{ date }}}). 4 | 5 | To check for potential problems, I ran `R CMD check` on your package {{{your_package}}} ({{{your_version}}}). 6 | 7 | I found: {{{your_summary}}}. 8 | 9 | {{#you_have_problems}} 10 | {{{your_results}}} 11 | 12 | If I got an ERROR because I couldn't install your package (or one of its dependencies), my apologies. You'll have to run the checks yourself (unfortunately I don't have the time to diagnose installation failures as I have to run checks on hundreds of packages). 13 | 14 | Otherwise, please carefully look at the results. If you think I've introduced a bug in dplyr, please file a reprex at . Otherwise, you'll need to prepare an update to your package following the advice in . 15 | 16 | To get the development version of {{{ my_package }}} so you can run the checks yourself, you can run: 17 | 18 | # install.packages("devtools") 19 | devtools::install_github("{{my_github}}") 20 | 21 | {{/you_have_problems}} 22 | {{^you_have_problems}} 23 | It looks like everything is ok with your package, so no action is necessary at this time. 24 | {{/you_have_problems}} 25 | 26 | If you have any questions about this email, please feel free to respond directly. 27 | 28 | Regards, 29 | 30 | {{{ me }}} 31 | -------------------------------------------------------------------------------- /inst/include/dplyr/DataFrameColumnSubsetVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_DataFrameColumnSubsetVisitors_H 2 | #define dplyr_DataFrameColumnSubsetVisitors_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | class DataFrameColumnSubsetVisitor : public SubsetVectorVisitor { 9 | public: 10 | DataFrameColumnSubsetVisitor(const DataFrame& data_) : data(data_), visitors(data) {} 11 | 12 | inline SEXP subset(const Rcpp::IntegerVector& index) const { 13 | return visitors.subset(index, get_class(data)); 14 | } 15 | 16 | inline SEXP subset(const std::vector& index) const { 17 | return visitors.subset(index, get_class(data)); 18 | } 19 | 20 | inline SEXP subset(const SlicingIndex& index) const { 21 | return visitors.subset(index, get_class(data)); 22 | } 23 | 24 | inline SEXP subset(const ChunkIndexMap& index) const { 25 | return visitors.subset(index, get_class(data)); 26 | } 27 | 28 | inline SEXP subset(EmptySubset index) const { 29 | return visitors.subset(index, get_class(data)); 30 | } 31 | 32 | inline int size() const { 33 | return visitors.nrows(); 34 | } 35 | 36 | inline std::string get_r_type() const { 37 | return "data.frame"; 38 | } 39 | 40 | inline bool is_compatible(SubsetVectorVisitor* other, std::stringstream&, const SymbolString&) const { 41 | return is_same_typeid(other); 42 | } 43 | 44 | private: 45 | DataFrame data; 46 | DataFrameSubsetVisitors visitors; 47 | }; 48 | 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /R/utils-expr.R: -------------------------------------------------------------------------------- 1 | 2 | expr_type_of <- function(x) { 3 | type <- typeof(x) 4 | if (type %in% c("symbol", "language", "pairlist", "NULL")) { 5 | type 6 | } else { 7 | "literal" 8 | } 9 | } 10 | switch_expr <- function(.x, ...) { 11 | switch(expr_type_of(.x), ...) 12 | } 13 | 14 | node_walk_replace <- function(node, old, new) { 15 | while (!is_null(node)) { 16 | switch_expr(node_car(node), 17 | language = node_walk_replace(node_cdar(node), old, new), 18 | symbol = if (identical(node_car(node), old)) mut_node_car(node, new) 19 | ) 20 | node <- node_cdr(node) 21 | } 22 | } 23 | expr_substitute <- function(expr, old, new) { 24 | expr <- duplicate(expr) 25 | switch_type(expr, 26 | quosure = node_walk_replace(quo_get_expr(expr), old, new), 27 | formula = , 28 | language = node_walk_replace(node_cdr(expr), old, new), 29 | symbol = if (identical(expr, old)) return(new) 30 | ) 31 | expr 32 | } 33 | 34 | sym_dollar <- quote(`$`) 35 | sym_brackets2 <- quote(`[[`) 36 | is_data_pronoun <- function(expr) { 37 | is_lang(expr, list(sym_dollar, sym_brackets2)) && 38 | identical(node_cadr(expr), quote(.data)) 39 | } 40 | tidy_text <- function(quo, width = 60L) { 41 | expr <- quo_get_expr(quo) 42 | if (is_data_pronoun(expr)) { 43 | as_string(node_cadr(node_cdr(expr))) 44 | } else { 45 | quo_text(quo, width = width) 46 | } 47 | } 48 | named_quos <- function(...) { 49 | quos <- quos(...) 50 | exprs_auto_name(quos, printer = tidy_text) 51 | } 52 | -------------------------------------------------------------------------------- /src/encoding.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | namespace dplyr { 8 | 9 | R_xlen_t get_first_reencode_pos(const CharacterVector& x) { 10 | R_xlen_t len = x.length(); 11 | for (R_xlen_t i = 0; i < len; ++i) { 12 | SEXP xi = x[i]; 13 | if (xi != NA_STRING && !IS_ASCII(xi) && !IS_UTF8(xi)) { 14 | return i; 15 | } 16 | } 17 | 18 | return len; 19 | } 20 | 21 | CharacterVector reencode_char(SEXP x) { 22 | if (Rf_isFactor(x)) return reencode_factor(x); 23 | 24 | CharacterVector ret(x); 25 | R_xlen_t first = get_first_reencode_pos(ret); 26 | if (first >= ret.length()) return ret; 27 | 28 | ret = clone(ret); 29 | 30 | R_xlen_t len = ret.length(); 31 | for (R_xlen_t i = first; i < len; ++i) { 32 | SEXP reti = ret[i]; 33 | if (reti != NA_STRING && !IS_ASCII(reti) && !IS_UTF8(reti)) { 34 | ret[i] = String(Rf_translateCharUTF8(reti), CE_UTF8); 35 | } 36 | } 37 | 38 | return ret; 39 | } 40 | 41 | CharacterVector reencode_factor(IntegerVector x) { 42 | CharacterVector levels(reencode_char(get_levels(x))); 43 | CharacterVector ret(x.length()); 44 | 45 | R_xlen_t nlevels = levels.length(); 46 | 47 | R_xlen_t len = x.length(); 48 | for (R_xlen_t i = 0; i < len; ++i) { 49 | int xi = x[i]; 50 | if (xi <= 0 || xi > nlevels) 51 | ret[i] = NA_STRING; 52 | else 53 | ret[i] = levels[xi - 1]; 54 | } 55 | 56 | return ret; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /R/src.r: -------------------------------------------------------------------------------- 1 | #' Create a "src" object 2 | #' 3 | #' `src()` is the standard constructor for srcs and `is.src()` tests. 4 | #' 5 | #' @keywords internal 6 | #' @export 7 | #' @param subclass name of subclass. "src" is an abstract base class, so you 8 | #' must supply this value. `src_` is automatically prepended to the 9 | #' class name 10 | #' @param ... fields used by object. 11 | #' 12 | #' These dots are evaluated with [explicit splicing][rlang::dots_list]. 13 | #' @param x object to test for "src"-ness. 14 | src <- function(subclass, ...) { 15 | subclass <- paste0("src_", subclass) 16 | structure(dots_list(...), class = c(subclass, "src")) 17 | } 18 | 19 | #' @rdname src 20 | #' @export 21 | is.src <- function(x) inherits(x, "src") 22 | 23 | #' @export 24 | print.src <- function(x, ...) { 25 | cat(format(x, ...), "\n", sep = "") 26 | } 27 | 28 | #' List all tbls provided by a source. 29 | #' 30 | #' This is a generic method which individual src's will provide methods for. 31 | #' Most methods will not be documented because it's usually pretty obvious what 32 | #' possible results will be. 33 | #' 34 | #' @param x a data src. 35 | #' @export 36 | #' @keywords internal 37 | src_tbls <- function(x) { 38 | UseMethod("src_tbls") 39 | } 40 | 41 | #' Figure out if two sources are the same (or two tbl have the same source) 42 | #' 43 | #' @param x,y src or tbls to test 44 | #' @return a logical flag 45 | #' @export 46 | #' @keywords internal 47 | same_src <- function(x, y) { 48 | UseMethod("same_src") 49 | } 50 | -------------------------------------------------------------------------------- /R/group-indices.R: -------------------------------------------------------------------------------- 1 | #' Group id. 2 | #' 3 | #' Generate a unique id for each group 4 | #' 5 | #' @keywords internal 6 | #' @seealso [group_by()] 7 | #' @param .data a tbl 8 | #' @inheritParams group_by 9 | #' @inheritParams filter 10 | #' @export 11 | #' @examples 12 | #' group_indices(mtcars, cyl) 13 | group_indices <- function(.data, ...) { 14 | UseMethod("group_indices") 15 | } 16 | #' @export 17 | group_indices.default <- function(.data, ...) { 18 | group_indices_(.data, .dots = compat_as_lazy_dots(...)) 19 | } 20 | #' @export 21 | #' @rdname se-deprecated 22 | group_indices_ <- function(.data, ..., .dots = list()) { 23 | UseMethod("group_indices_") 24 | } 25 | 26 | #' @export 27 | group_indices.data.frame <- function(.data, ...) { 28 | dots <- quos(...) 29 | if (length(dots) == 0L) { 30 | return(rep(1L, nrow(.data))) 31 | } 32 | grouped_indices_grouped_df_impl(group_by(.data, !!! dots)) 33 | } 34 | #' @export 35 | group_indices_.data.frame <- function(.data, ..., .dots = list()) { 36 | dots <- compat_lazy_dots(.dots, caller_env(), ...) 37 | group_indices(.data, !!! dots) 38 | } 39 | 40 | #' @export 41 | group_indices.grouped_df <- function(.data, ...) { 42 | if (length(list(...))) { 43 | warn("group_indices_.grouped_df ignores extra arguments") 44 | } 45 | grouped_indices_grouped_df_impl(.data) 46 | } 47 | #' @export 48 | group_indices_.grouped_df <- function(.data, ..., .dots = list()) { 49 | dots <- compat_lazy_dots(.dots, caller_env(), ...) 50 | group_indices(.data, !!! dots) 51 | } 52 | -------------------------------------------------------------------------------- /R/reexport-tibble.r: -------------------------------------------------------------------------------- 1 | # dataframe --------------------------------------------------------------- 2 | 3 | #' @importFrom tibble data_frame 4 | #' @export 5 | tibble::data_frame 6 | 7 | #' @importFrom tibble data_frame_ 8 | #' @export 9 | tibble::data_frame_ 10 | 11 | #' @importFrom tibble as_data_frame 12 | #' @export 13 | tibble::as_data_frame 14 | 15 | #' @importFrom tibble lst 16 | #' @export 17 | tibble::lst 18 | 19 | #' @importFrom tibble lst_ 20 | #' @export 21 | tibble::lst_ 22 | 23 | #' @importFrom tibble add_row 24 | #' @export 25 | tibble::add_row 26 | 27 | # type_sum ---------------------------------------------------------------- 28 | 29 | #' @importFrom tibble type_sum 30 | #' @export 31 | tibble::type_sum 32 | 33 | # glimpse ----------------------------------------------------------------- 34 | 35 | #' @importFrom tibble glimpse 36 | #' @export 37 | tibble::glimpse 38 | 39 | # frame-data -------------------------------------------------------------- 40 | 41 | #' @importFrom tibble frame_data 42 | #' @export 43 | tibble::frame_data 44 | 45 | #' @importFrom tibble tribble 46 | #' @export 47 | tibble::tribble 48 | 49 | #' @importFrom tibble tibble 50 | #' @export 51 | tibble::tibble 52 | 53 | #' @importFrom tibble as_tibble 54 | #' @export 55 | tibble::as_tibble 56 | 57 | # utils ------------------------------------------------------------------- 58 | 59 | #' @importFrom tibble trunc_mat 60 | #' @export 61 | tibble::trunc_mat 62 | 63 | #' @importFrom tibble tbl_sum 64 | #' @export 65 | tibble::tbl_sum 66 | -------------------------------------------------------------------------------- /inst/include/dplyr/train.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_train_h 2 | #define dplyr_train_h 3 | 4 | namespace dplyr { 5 | 6 | template 7 | inline void iterate_with_interupts(Op op, int n) { 8 | int i = 0; 9 | if (n > DPLYR_MIN_INTERUPT_SIZE) { 10 | int m = n / DPLYR_INTERUPT_TIMES; 11 | for (int k = 0; k < DPLYR_INTERUPT_TIMES; k++) { 12 | for (int j = 0; j < m; j++, i++) op(i); 13 | Rcpp::checkUserInterrupt(); 14 | } 15 | } 16 | for (; i < n; i++) op(i); 17 | } 18 | 19 | template 20 | struct push_back_op { 21 | push_back_op(Map& map_) : map(map_) {} 22 | inline void operator()(int i) { 23 | map[i].push_back(i); 24 | } 25 | Map& map; 26 | }; 27 | 28 | template 29 | struct push_back_right_op { 30 | push_back_right_op(Map& map_) : map(map_) {} 31 | inline void operator()(int i) { 32 | map[-i - 1].push_back(-i - 1); 33 | } 34 | Map& map; 35 | }; 36 | 37 | 38 | template 39 | inline void train_push_back(Map& map, int n) { 40 | iterate_with_interupts(push_back_op(map), n); 41 | } 42 | 43 | template 44 | inline void train_push_back_right(Map& map, int n) { 45 | iterate_with_interupts(push_back_right_op(map), n); 46 | } 47 | 48 | template 49 | inline void train_insert(Set& set, int n) { 50 | for (int i = 0; i < n; i++) set.insert(i); 51 | } 52 | template 53 | inline void train_insert_right(Set& set, int n) { 54 | for (int i = 0; i < n; i++) set.insert(-i - 1); 55 | } 56 | 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /inst/include/tools/SymbolString.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_tools_SymbolString_h 2 | #define dplyr_tools_SymbolString_h 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | class SymbolString { 9 | public: 10 | SymbolString() {} 11 | 12 | SymbolString(const char* str) : s(str) {} 13 | 14 | SymbolString(const String& other) : s(other) {} 15 | 16 | SymbolString(const String::StringProxy& other) : s(other) {} 17 | 18 | SymbolString(const String::const_StringProxy& other) : s(other) {} 19 | 20 | // Symbols are always encoded in the native encoding (#1950) 21 | explicit SymbolString(const Symbol& symbol) : s(CHAR(PRINTNAME(symbol)), CE_NATIVE) {} 22 | 23 | public: 24 | const String& get_string() const { 25 | return s; 26 | } 27 | 28 | const Symbol get_symbol() const { 29 | return Symbol(Rf_translateChar(s.get_sexp())); 30 | } 31 | 32 | const std::string get_utf8_cstring() const { 33 | static Environment rlang = Environment::namespace_env("rlang"); 34 | static Function as_string = Function("as_string", rlang); 35 | SEXP utf8_string = as_string(Rf_lang2(R_QuoteSymbol, get_symbol())); 36 | return CHAR(STRING_ELT(utf8_string, 0)); 37 | } 38 | 39 | bool is_empty() const { 40 | return s == ""; 41 | } 42 | 43 | SEXP get_sexp() const { 44 | return s.get_sexp(); 45 | } 46 | 47 | bool operator==(const SymbolString& other) const { 48 | return Rf_NonNullStringMatch(get_sexp(), other.get_sexp()); 49 | } 50 | 51 | private: 52 | String s; 53 | }; 54 | 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /man/summarise_each.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/colwise-mutate.R 3 | \name{summarise_each} 4 | \alias{summarise_each} 5 | \alias{summarise_each_} 6 | \alias{mutate_each} 7 | \alias{mutate_each_} 8 | \alias{summarize_each} 9 | \alias{summarize_each_} 10 | \title{Summarise and mutate multiple columns.} 11 | \usage{ 12 | summarise_each(tbl, funs, ...) 13 | 14 | summarise_each_(tbl, funs, vars) 15 | 16 | mutate_each(tbl, funs, ...) 17 | 18 | mutate_each_(tbl, funs, vars) 19 | 20 | summarize_each(tbl, funs, ...) 21 | 22 | summarize_each_(tbl, funs, vars) 23 | } 24 | \description{ 25 | \code{mutate_each()} and \code{summarise_each()} are deprecated in favour of 26 | a more featureful family of functions: \code{\link[=mutate_all]{mutate_all()}}, 27 | \code{\link[=mutate_at]{mutate_at()}}, \code{\link[=mutate_if]{mutate_if()}}, \code{\link[=summarise_all]{summarise_all()}}, \code{\link[=summarise_at]{summarise_at()}} 28 | and \code{\link[=summarise_if]{summarise_if()}}. 29 | 30 | The \code{_each()} functions have two replacements depending on what 31 | variables you want to apply \code{funs} to. To apply a function to all 32 | variables, use \code{\link[=mutate_all]{mutate_all()}} or \code{\link[=summarise_all]{summarise_all()}}. To apply a 33 | function to a selection of variables, use \code{\link[=mutate_at]{mutate_at()}} or 34 | \code{\link[=summarise_at]{summarise_at()}}. 35 | 36 | See the relevant section of \code{vignette("compatibility")} for more 37 | information. 38 | } 39 | \keyword{internal} 40 | -------------------------------------------------------------------------------- /R/coalesce.R: -------------------------------------------------------------------------------- 1 | #' Find first non-missing element 2 | #' 3 | #' Given a set of vectors, `coalesce()` finds the first non-missing value 4 | #' at each position. This is inspired by the SQL `COALESCE` function 5 | #' which does the same thing for `NULL`s. 6 | #' 7 | #' @param ... Vectors. All inputs should either be length 1, or the 8 | #' same length as the first argument. 9 | #' 10 | #' These dots support [tidy dots][rlang::tidy-dots] features. 11 | #' @return A vector the same length as the first `...` argument with 12 | #' missing values replaced by the first non-missing value. 13 | #' @seealso [na_if()] to replace specified values with a `NA`. 14 | #' @export 15 | #' @examples 16 | #' # Use a single value to replace all missing values 17 | #' x <- sample(c(1:5, NA, NA, NA)) 18 | #' coalesce(x, 0L) 19 | #' 20 | #' # Or match together a complete vector from missing pieces 21 | #' y <- c(1, 2, NA, NA, 5) 22 | #' z <- c(NA, NA, 3, 4, 5) 23 | #' coalesce(y, z) 24 | #' 25 | #' # Supply lists by splicing them into dots: 26 | #' vecs <- list( 27 | #' c(1, 2, NA, NA, 5), 28 | #' c(NA, NA, 3, 4, 5) 29 | #' ) 30 | #' coalesce(!!! vecs) 31 | coalesce <- function(...) { 32 | if (missing(..1)) { 33 | abort("At least one argument must be supplied") 34 | } 35 | 36 | values <- list2(...) 37 | x <- values[[1]] 38 | values <- values[-1] 39 | 40 | for (i in seq_along(values)) { 41 | x <- replace_with( 42 | x, is.na(x), values[[i]], 43 | glue("Argument {i + 1}"), 44 | glue("length of {fmt_args(~x)}") 45 | ) 46 | } 47 | x 48 | } 49 | -------------------------------------------------------------------------------- /R/explain.r: -------------------------------------------------------------------------------- 1 | #' Explain details of a tbl 2 | #' 3 | #' This is a generic function which gives more details about an object than 4 | #' [print()], and is more focused on human readable output than 5 | #' [str()]. 6 | #' 7 | #' @section Databases: 8 | #' Explaining a `tbl_sql` will run the SQL `EXPLAIN` command which 9 | #' will describe the query plan. This requires a little bit of knowledge about 10 | #' how `EXPLAIN` works for your database, but is very useful for 11 | #' diagnosing performance problems. 12 | #' 13 | #' @export 14 | #' @param x An object to explain 15 | #' @param ... Other parameters possibly used by generic 16 | #' @return The first argument, invisibly. 17 | #' @examples 18 | #' \donttest{ 19 | #' if (require("dbplyr")) { 20 | #' 21 | #' lahman_s <- lahman_sqlite() 22 | #' batting <- tbl(lahman_s, "Batting") 23 | #' batting %>% show_query() 24 | #' batting %>% explain() 25 | #' 26 | #' # The batting database has indices on all ID variables: 27 | #' # SQLite automatically picks the most restrictive index 28 | #' batting %>% filter(lgID == "NL" & yearID == 2000L) %>% explain() 29 | #' 30 | #' # OR's will use multiple indexes 31 | #' batting %>% filter(lgID == "NL" | yearID == 2000) %>% explain() 32 | #' 33 | #' # Joins will use indexes in both tables 34 | #' teams <- tbl(lahman_s, "Teams") 35 | #' batting %>% left_join(teams, c("yearID", "teamID")) %>% explain() 36 | #' } 37 | #' } 38 | explain <- function(x, ...) { 39 | UseMethod("explain") 40 | } 41 | 42 | #' @export 43 | #' @rdname explain 44 | show_query <- function(x, ...) { 45 | UseMethod("show_query") 46 | } 47 | -------------------------------------------------------------------------------- /tests/testthat/helper-encoding.R: -------------------------------------------------------------------------------- 1 | get_lang_strings <- function() { 2 | lang_strings <- c( 3 | de = "Gl\u00fcck", 4 | cn = "\u5e78\u798f", 5 | ru = "\u0441\u0447\u0430\u0441\u0442\u044c\u0435", 6 | ko = "\ud589\ubcf5" 7 | ) 8 | 9 | native_lang_strings <- enc2native(lang_strings) 10 | 11 | same <- (lang_strings == native_lang_strings) 12 | 13 | list( 14 | same = lang_strings[same], 15 | different = lang_strings[!same] 16 | ) 17 | } 18 | 19 | get_native_lang_string <- function() { 20 | lang_strings <- get_lang_strings() 21 | if (length(lang_strings$same) == 0) testthat::skip("No native language string available") 22 | lang_strings$same[[1L]] 23 | } 24 | 25 | get_alien_lang_string <- function() { 26 | lang_strings <- get_lang_strings() 27 | if (length(lang_strings$different) == 0) testthat::skip("No alien language string available") 28 | lang_strings$different[[1L]] 29 | } 30 | 31 | with_non_utf8_encoding <- function(code) { 32 | old_encoding <- set_non_utf8_encoding() 33 | on.exit(set_encoding(old_encoding), add = TRUE) 34 | code 35 | } 36 | 37 | set_non_utf8_encoding <- function() { 38 | if (.Platform$OS.type == "windows") return(NULL) 39 | tryCatch( 40 | locale <- set_encoding("en_US.ISO88591"), 41 | warning = function(e) { 42 | testthat::skip("Cannot set latin-1 encoding") 43 | } 44 | ) 45 | locale 46 | } 47 | 48 | set_encoding <- function(encoding) { 49 | if (is.null(encoding)) return(NULL) 50 | locale <- Sys.getlocale("LC_CTYPE") 51 | Sys.setlocale("LC_CTYPE", encoding) 52 | locale 53 | } 54 | -------------------------------------------------------------------------------- /man/compute.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compute-collect.r 3 | \name{compute} 4 | \alias{compute} 5 | \alias{collect} 6 | \alias{collapse} 7 | \title{Force computation of a database query} 8 | \usage{ 9 | compute(x, name = random_table_name(), ...) 10 | 11 | collect(x, ...) 12 | 13 | collapse(x, ...) 14 | } 15 | \arguments{ 16 | \item{x}{A tbl} 17 | 18 | \item{name}{Name of temporary table on database.} 19 | 20 | \item{...}{Other arguments passed on to methods} 21 | } 22 | \description{ 23 | \code{compute()} stores results in a remote temporary table. 24 | \code{collect()} retrieves data into a local tibble. 25 | \code{collapse()} is slightly different: it doesn't force computation, but 26 | instead forces generation of the SQL query. This is sometimes needed to work 27 | around bugs in dplyr's SQL generation. 28 | } 29 | \details{ 30 | All functions preserve grouping and ordering. 31 | } 32 | \examples{ 33 | if (require(dbplyr)) { 34 | mtcars2 <- src_memdb() \%>\% 35 | copy_to(mtcars, name = "mtcars2-cc", overwrite = TRUE) 36 | 37 | remote <- mtcars2 \%>\% 38 | filter(cyl == 8) \%>\% 39 | select(mpg:drat) 40 | 41 | # Compute query and save in remote table 42 | compute(remote) 43 | 44 | # Compute query bring back to this session 45 | collect(remote) 46 | 47 | # Creates a fresh query based on the generated SQL 48 | collapse(remote) 49 | } 50 | } 51 | \seealso{ 52 | \code{\link[=copy_to]{copy_to()}}, the opposite of \code{collect()}: it takes a local data 53 | frame and uploads it to the remote source. 54 | } 55 | -------------------------------------------------------------------------------- /man/if_else.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/if_else.R 3 | \name{if_else} 4 | \alias{if_else} 5 | \title{Vectorised if} 6 | \usage{ 7 | if_else(condition, true, false, missing = NULL) 8 | } 9 | \arguments{ 10 | \item{condition}{Logical vector} 11 | 12 | \item{true, false}{Values to use for \code{TRUE} and \code{FALSE} values of 13 | \code{condition}. They must be either the same length as \code{condition}, 14 | or length 1. They must also be the same type: \code{if_else()} checks that 15 | they have the same type and same class. All other attributes are 16 | taken from \code{true}.} 17 | 18 | \item{missing}{If not \code{NULL}, will be used to replace missing 19 | values.} 20 | } 21 | \value{ 22 | Where \code{condition} is \code{TRUE}, the matching value from 23 | \code{true}, where it's \code{FALSE}, the matching value from \code{false}, 24 | otherwise \code{NA}. 25 | } 26 | \description{ 27 | Compared to the base \code{\link[=ifelse]{ifelse()}}, this function is more strict. 28 | It checks that \code{true} and \code{false} are the same type. This 29 | strictness makes the output type more predictable, and makes it somewhat 30 | faster. 31 | } 32 | \examples{ 33 | x <- c(-5:5, NA) 34 | if_else(x < 0, NA_integer_, x) 35 | if_else(x < 0, "negative", "positive", "missing") 36 | 37 | # Unlike ifelse, if_else preserves types 38 | x <- factor(sample(letters[1:5], 10, replace = TRUE)) 39 | ifelse(x \%in\% c("a", "b", "c"), x, factor(NA)) 40 | if_else(x \%in\% c("a", "b", "c"), x, factor(NA)) 41 | # Attributes are taken from the `true` vector, 42 | } 43 | -------------------------------------------------------------------------------- /inst/include/dplyr/Result/Mutater.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Result_Mutater_H 2 | #define dplyr_Result_Mutater_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | template 9 | class Mutater : public Result { 10 | public: 11 | 12 | virtual SEXP process(const GroupedDataFrame& gdf) { 13 | int ng = gdf.ngroups(); 14 | 15 | Vector out = no_init(gdf.nrows()); 16 | GroupedDataFrame::group_iterator git = gdf.group_begin(); 17 | for (int i = 0; i < ng; i++, ++git) { 18 | static_cast(*this).process_slice(out, *git, *git); 19 | } 20 | return out; 21 | } 22 | 23 | virtual SEXP process(const RowwiseDataFrame& gdf) { 24 | int ng = gdf.ngroups(); 25 | 26 | Vector out = no_init(gdf.nrows()); 27 | RowwiseDataFrame::group_iterator git = gdf.group_begin(); 28 | for (int i = 0; i < ng; i++, ++git) { 29 | static_cast(*this).process_slice(out, *git, *git); 30 | } 31 | return out; 32 | } 33 | 34 | virtual SEXP process(const FullDataFrame& df) { 35 | Vector out = no_init(df.nrows()); 36 | const SlicingIndex& index = df.get_index(); 37 | static_cast(*this).process_slice(out, index, index); 38 | return out; 39 | } 40 | 41 | virtual SEXP process(const SlicingIndex& index) { 42 | int nrows = index.size(); 43 | Vector out = no_init(nrows); 44 | NaturalSlicingIndex fake(nrows); 45 | static_cast(*this).process_slice(out, index, fake); 46 | return out; 47 | } 48 | 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /man/distinct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/distinct.R 3 | \name{distinct} 4 | \alias{distinct} 5 | \title{Select distinct/unique rows} 6 | \usage{ 7 | distinct(.data, ..., .keep_all = FALSE) 8 | } 9 | \arguments{ 10 | \item{.data}{a tbl} 11 | 12 | \item{...}{Optional variables to use when determining uniqueness. If there 13 | are multiple rows for a given combination of inputs, only the first 14 | row will be preserved. If omitted, will use all variables.} 15 | 16 | \item{.keep_all}{If \code{TRUE}, keep all variables in \code{.data}. 17 | If a combination of \code{...} is not distinct, this keeps the 18 | first row of values.} 19 | } 20 | \description{ 21 | Retain only unique/distinct rows from an input tbl. This is similar 22 | to \code{\link[=unique.data.frame]{unique.data.frame()}}, but considerably faster. 23 | } 24 | \examples{ 25 | df <- tibble( 26 | x = sample(10, 100, rep = TRUE), 27 | y = sample(10, 100, rep = TRUE) 28 | ) 29 | nrow(df) 30 | nrow(distinct(df)) 31 | nrow(distinct(df, x, y)) 32 | 33 | distinct(df, x) 34 | distinct(df, y) 35 | 36 | # Can choose to keep all other variables as well 37 | distinct(df, x, .keep_all = TRUE) 38 | distinct(df, y, .keep_all = TRUE) 39 | 40 | # You can also use distinct on computed variables 41 | distinct(df, diff = abs(x - y)) 42 | 43 | # The same behaviour applies for grouped data frames 44 | # except that the grouping variables are always included 45 | df <- tibble( 46 | g = c(1, 1, 2, 2), 47 | x = c(1, 1, 2, 1) 48 | ) \%>\% group_by(g) 49 | df \%>\% distinct() 50 | df \%>\% distinct(x) 51 | } 52 | -------------------------------------------------------------------------------- /R/compute-collect.r: -------------------------------------------------------------------------------- 1 | #' Force computation of a database query 2 | #' 3 | #' `compute()` stores results in a remote temporary table. 4 | #' `collect()` retrieves data into a local tibble. 5 | #' `collapse()` is slightly different: it doesn't force computation, but 6 | #' instead forces generation of the SQL query. This is sometimes needed to work 7 | #' around bugs in dplyr's SQL generation. 8 | #' 9 | #' All functions preserve grouping and ordering. 10 | #' 11 | #' @param x A tbl 12 | #' @param name Name of temporary table on database. 13 | #' @param ... Other arguments passed on to methods 14 | #' @inheritParams copy_to.src_sql 15 | #' @seealso [copy_to()], the opposite of `collect()`: it takes a local data 16 | #' frame and uploads it to the remote source. 17 | #' @export 18 | #' @examples 19 | #' if (require(dbplyr)) { 20 | #' mtcars2 <- src_memdb() %>% 21 | #' copy_to(mtcars, name = "mtcars2-cc", overwrite = TRUE) 22 | #' 23 | #' remote <- mtcars2 %>% 24 | #' filter(cyl == 8) %>% 25 | #' select(mpg:drat) 26 | #' 27 | #' # Compute query and save in remote table 28 | #' compute(remote) 29 | #' 30 | #' # Compute query bring back to this session 31 | #' collect(remote) 32 | #' 33 | #' # Creates a fresh query based on the generated SQL 34 | #' collapse(remote) 35 | #' } 36 | compute <- function(x, name = random_table_name(), ...) { 37 | UseMethod("compute") 38 | } 39 | 40 | #' @export 41 | #' @rdname compute 42 | collect <- function(x, ...) { 43 | UseMethod("collect") 44 | } 45 | 46 | #' @export 47 | #' @rdname compute 48 | collapse <- function(x, ...) { 49 | UseMethod("collapse") 50 | } 51 | -------------------------------------------------------------------------------- /R/hybrid.R: -------------------------------------------------------------------------------- 1 | verify_hybrid <- function(x) { 2 | abort("Not in hybrid evaluation") 3 | } 4 | 5 | verify_not_hybrid <- function(x) { 6 | x 7 | } 8 | 9 | with_hybrid <- function(expr, ...) { 10 | expr <- enquo(expr) 11 | stopifnot(any(class(expr) == "formula")) 12 | expr[[2]] <- prepend_call(expr[[2]], "verify_hybrid") 13 | data <- data_frame(...) 14 | 15 | # Make verify_hybrid() available to the evaluated expression 16 | eval_env <- new.env(parent = environment(expr)) 17 | eval_env$verify_hybrid <- verify_hybrid 18 | environment(expr) <- eval_env 19 | 20 | summarise(data, out = !! expr)["out"][[1]] 21 | } 22 | 23 | without_hybrid <- function(expr, ...) { 24 | expr <- enquo(expr) 25 | stopifnot(any(class(expr) == "formula")) 26 | expr[[2]] <- prepend_call(expr[[2]], "verify_not_hybrid") 27 | data <- data_frame(...) 28 | 29 | # Make verify_not_hybrid() available to the evaluated expression 30 | eval_env <- new.env(parent = environment(expr)) 31 | eval_env$verify_not_hybrid <- verify_not_hybrid 32 | environment(expr) <- eval_env 33 | 34 | summarise(data, out = !! expr)["out"][[1]] 35 | } 36 | 37 | eval_dots <- function(expr, ...) { 38 | expr <- enquo(expr) 39 | data <- data_frame(...) 40 | eval(expr[[2]], data, enclos = environment(expr)) 41 | } 42 | 43 | # some(func()) -> name(some(func())) 44 | # list(some(func())) -> list(name(some(func()))) 45 | prepend_call <- function(expr, name) { 46 | if (is.call(expr) && expr[[1]] == quote(list)) { 47 | stopifnot(length(expr) == 2L) 48 | call("list", call(name, expr[[2]])) 49 | } else { 50 | call(name, expr) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /R/sets.r: -------------------------------------------------------------------------------- 1 | #' Set operations 2 | #' 3 | #' These functions override the set functions provided in base to make them 4 | #' generic so that efficient versions for data frames and other tables can be 5 | #' provided. The default methods call the base versions. 6 | #' 7 | #' @param x,y objects to perform set function on (ignoring order) 8 | #' @param ... other arguments passed on to methods 9 | #' @name setops 10 | #' @examples 11 | #' mtcars$model <- rownames(mtcars) 12 | #' first <- mtcars[1:20, ] 13 | #' second <- mtcars[10:32, ] 14 | #' 15 | #' intersect(first, second) 16 | #' union(first, second) 17 | #' setdiff(first, second) 18 | #' setdiff(second, first) 19 | #' 20 | #' union_all(first, second) 21 | #' setequal(mtcars, mtcars[32:1, ]) 22 | NULL 23 | 24 | #' @rdname setops 25 | #' @export 26 | intersect <- function(x, y, ...) UseMethod("intersect") 27 | #' @rdname setops 28 | #' @export 29 | union <- function(x, y, ...) UseMethod("union") 30 | #' @rdname setops 31 | #' @export 32 | union_all <- function(x, y, ...) UseMethod("union_all") 33 | #' @rdname setops 34 | #' @export 35 | setdiff <- function(x, y, ...) UseMethod("setdiff") 36 | #' @rdname setops 37 | #' @export 38 | setequal <- function(x, y, ...) UseMethod("setequal") 39 | 40 | #' @export 41 | intersect.default <- function(x, y, ...) base::intersect(x, y, ...) 42 | #' @export 43 | union.default <- function(x, y, ...) base::union(x, y, ...) 44 | #' @export 45 | union_all.default <- function(x, y, ...) combine(x, y, ...) 46 | #' @export 47 | setdiff.default <- function(x, y, ...) base::setdiff(x, y, ...) 48 | #' @export 49 | setequal.default <- function(x, y, ...) base::setequal(x, y, ...) 50 | -------------------------------------------------------------------------------- /man/explain.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/explain.r 3 | \name{explain} 4 | \alias{explain} 5 | \alias{show_query} 6 | \title{Explain details of a tbl} 7 | \usage{ 8 | explain(x, ...) 9 | 10 | show_query(x, ...) 11 | } 12 | \arguments{ 13 | \item{x}{An object to explain} 14 | 15 | \item{...}{Other parameters possibly used by generic} 16 | } 17 | \value{ 18 | The first argument, invisibly. 19 | } 20 | \description{ 21 | This is a generic function which gives more details about an object than 22 | \code{\link[=print]{print()}}, and is more focused on human readable output than 23 | \code{\link[=str]{str()}}. 24 | } 25 | \section{Databases}{ 26 | 27 | Explaining a \code{tbl_sql} will run the SQL \code{EXPLAIN} command which 28 | will describe the query plan. This requires a little bit of knowledge about 29 | how \code{EXPLAIN} works for your database, but is very useful for 30 | diagnosing performance problems. 31 | } 32 | 33 | \examples{ 34 | \donttest{ 35 | if (require("dbplyr")) { 36 | 37 | lahman_s <- lahman_sqlite() 38 | batting <- tbl(lahman_s, "Batting") 39 | batting \%>\% show_query() 40 | batting \%>\% explain() 41 | 42 | # The batting database has indices on all ID variables: 43 | # SQLite automatically picks the most restrictive index 44 | batting \%>\% filter(lgID == "NL" & yearID == 2000L) \%>\% explain() 45 | 46 | # OR's will use multiple indexes 47 | batting \%>\% filter(lgID == "NL" | yearID == 2000) \%>\% explain() 48 | 49 | # Joins will use indexes in both tables 50 | teams <- tbl(lahman_s, "Teams") 51 | batting \%>\% left_join(teams, c("yearID", "teamID")) \%>\% explain() 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /inst/include/dplyr/MultipleVectorVisitors.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_MultipleVectorVisitors_H 2 | #define dplyr_MultipleVectorVisitors_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace dplyr { 11 | 12 | class MultipleVectorVisitors : 13 | public VisitorSetEqual, 14 | public VisitorSetHash, 15 | public VisitorSetLess, 16 | public VisitorSetGreater { 17 | 18 | private: 19 | std::vector< boost::shared_ptr > visitors; 20 | 21 | public: 22 | typedef VectorVisitor visitor_type; 23 | 24 | MultipleVectorVisitors() : visitors() {} 25 | 26 | MultipleVectorVisitors(List data) : 27 | visitors() 28 | { 29 | int n = data.size(); 30 | for (int i = 0; i < n; i++) { 31 | push_back(data[i]); 32 | } 33 | } 34 | 35 | inline int size() const { 36 | return visitors.size(); 37 | } 38 | inline VectorVisitor* get(int k) const { 39 | return visitors[k].get(); 40 | } 41 | inline int nrows() const { 42 | if (visitors.size() == 0) { 43 | stop("Need at least one column for `nrows()`"); 44 | } 45 | return visitors[0]->size(); 46 | } 47 | inline void push_back(SEXP x) { 48 | visitors.push_back(boost::shared_ptr(visitor(x))); 49 | } 50 | 51 | inline bool is_na(int index) const { 52 | int n = size(); 53 | for (int i = 0; i < n; i++) if (visitors[i]->is_na(index)) return true; 54 | return false; 55 | } 56 | 57 | }; 58 | 59 | } // namespace dplyr 60 | 61 | #include 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /R/utils-replace-with.R: -------------------------------------------------------------------------------- 1 | replace_with <- function(x, i, val, name, reason = NULL) { 2 | if (is.null(val)) { 3 | return(x) 4 | } 5 | 6 | check_length(val, x, name, reason) 7 | check_type(val, x, name) 8 | check_class(val, x, name) 9 | 10 | i[is.na(i)] <- FALSE 11 | 12 | if (length(val) == 1L) { 13 | x[i] <- val 14 | } else { 15 | x[i] <- val[i] 16 | } 17 | 18 | x 19 | } 20 | 21 | check_length <- function(x, template, header, reason = NULL) { 22 | check_length_val(length(x), length(template), header, reason) 23 | } 24 | 25 | check_length_col <- function(length_x, n, name, reason = NULL, .abort = abort) { 26 | check_length_val(length_x, n, fmt_cols(name), reason, .abort = .abort) 27 | } 28 | 29 | check_length_val <- function(length_x, n, header, reason = NULL, .abort = abort) { 30 | if (all(length_x %in% c(1L, n))) { 31 | return() 32 | } 33 | 34 | if (is.null(reason)) reason <- "" 35 | else reason <- glue(" ({reason})") 36 | 37 | if (n == 1) { 38 | glubort(header, "must be length 1{reason}, not {commas(length_x)}", .abort = .abort) 39 | } else { 40 | glubort(header, "must be length {n}{reason} or one, not {commas(length_x)}", .abort = .abort) 41 | } 42 | } 43 | 44 | check_type <- function(x, template, header) { 45 | if (identical(typeof(x), typeof(template))) { 46 | return() 47 | } 48 | 49 | glubort(header, "must be type {type_of(template)}, not {typeof(x)}") 50 | } 51 | 52 | check_class <- function(x, template, header) { 53 | if (!is.object(x)) { 54 | return() 55 | } 56 | 57 | if (identical(class(x), class(template))) { 58 | return() 59 | } 60 | 61 | glubort(header, "must be {fmt_classes(template)}, not {fmt_classes(x)}") 62 | } 63 | -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reexport-tibble.r, R/reexport-tidyselect.R, 3 | % R/utils.r 4 | \docType{import} 5 | \name{reexports} 6 | \alias{reexports} 7 | \alias{data_frame} 8 | \alias{data_frame_} 9 | \alias{as_data_frame} 10 | \alias{lst} 11 | \alias{lst_} 12 | \alias{add_row} 13 | \alias{type_sum} 14 | \alias{glimpse} 15 | \alias{frame_data} 16 | \alias{tribble} 17 | \alias{tibble} 18 | \alias{as_tibble} 19 | \alias{trunc_mat} 20 | \alias{tbl_sum} 21 | \alias{contains} 22 | \alias{ends_with} 23 | \alias{everything} 24 | \alias{matches} 25 | \alias{num_range} 26 | \alias{one_of} 27 | \alias{starts_with} 28 | \alias{\%>\%} 29 | \title{Objects exported from other packages} 30 | \keyword{internal} 31 | \description{ 32 | These objects are imported from other packages. Follow the links 33 | below to see their documentation. 34 | 35 | \describe{ 36 | \item{magrittr}{\code{\link[magrittr]{\%>\%}}} 37 | 38 | \item{tibble}{\code{\link[tibble]{data_frame}}, \code{\link[tibble]{data_frame_}}, \code{\link[tibble]{as_data_frame}}, \code{\link[tibble]{lst}}, \code{\link[tibble]{lst_}}, \code{\link[tibble]{add_row}}, \code{\link[tibble]{type_sum}}, \code{\link[tibble]{glimpse}}, \code{\link[tibble]{frame_data}}, \code{\link[tibble]{tribble}}, \code{\link[tibble]{tibble}}, \code{\link[tibble]{as_tibble}}, \code{\link[tibble]{trunc_mat}}, \code{\link[tibble]{tbl_sum}}} 39 | 40 | \item{tidyselect}{\code{\link[tidyselect]{contains}}, \code{\link[tidyselect]{ends_with}}, \code{\link[tidyselect]{everything}}, \code{\link[tidyselect]{matches}}, \code{\link[tidyselect]{num_range}}, \code{\link[tidyselect]{one_of}}, \code{\link[tidyselect]{starts_with}}} 41 | }} 42 | 43 | -------------------------------------------------------------------------------- /inst/include/dplyr/Replicator.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_Replicator_H 2 | #define dplyr_Replicator_H 3 | 4 | #include 5 | 6 | namespace dplyr { 7 | 8 | class Replicator { 9 | public: 10 | virtual ~Replicator() {} 11 | virtual SEXP collect() = 0; 12 | }; 13 | 14 | template 15 | class ReplicatorImpl : public Replicator { 16 | public: 17 | typedef typename Rcpp::traits::storage_type::type STORAGE; 18 | 19 | ReplicatorImpl(SEXP v, int n_, int ngroups_) : 20 | data(no_init(n_ * ngroups_)), source(v), n(n_), ngroups(ngroups_) {} 21 | 22 | SEXP collect() { 23 | for (int i = 0, k = 0; i < ngroups; i++) { 24 | for (int j = 0; j < n; j++, k++) { 25 | data[k] = source[j]; 26 | } 27 | } 28 | copy_most_attributes(data, source); 29 | return data; 30 | } 31 | 32 | private: 33 | Vector data; 34 | Vector source; 35 | int n; 36 | int ngroups; 37 | }; 38 | 39 | template 40 | inline Replicator* replicator(SEXP v, const Data& gdf) { 41 | int n = Rf_length(v); 42 | switch (TYPEOF(v)) { 43 | case INTSXP: 44 | return new ReplicatorImpl (v, n, gdf.ngroups()); 45 | case REALSXP: 46 | return new ReplicatorImpl (v, n, gdf.ngroups()); 47 | case STRSXP: 48 | return new ReplicatorImpl (v, n, gdf.ngroups()); 49 | case LGLSXP: 50 | return new ReplicatorImpl (v, n, gdf.ngroups()); 51 | case CPLXSXP: 52 | return new ReplicatorImpl (v, n, gdf.ngroups()); 53 | default: 54 | break; 55 | } 56 | 57 | stop("is of unsupported type %s", Rf_type2char(TYPEOF(v))); 58 | } 59 | 60 | } // namespace dplyr 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /inst/include/dplyr/SubsetVectorVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef dplyr_SubsetVectorVisitor_H 2 | #define dplyr_SubsetVectorVisitor_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace dplyr { 9 | 10 | template 11 | inline int output_size(const Container& container) { 12 | return container.size(); 13 | } 14 | 15 | /** 16 | * Subset Vector visitor base class, defines the interface 17 | */ 18 | class SubsetVectorVisitor { 19 | public: 20 | virtual ~SubsetVectorVisitor() {} 21 | 22 | /** creates a new vector, of the same type as the visited vector, by 23 | * copying elements at the given indices 24 | */ 25 | virtual SEXP subset(const Rcpp::IntegerVector& index) const = 0; 26 | 27 | virtual SEXP subset(const std::vector&) const = 0; 28 | 29 | virtual SEXP subset(const SlicingIndex&) const = 0; 30 | 31 | /** creates a new vector, of the same type as the visited vector, by 32 | * copying elements at the given indices 33 | */ 34 | virtual SEXP subset(const ChunkIndexMap& index) const = 0; 35 | 36 | virtual SEXP subset(EmptySubset) const = 0; 37 | 38 | virtual int size() const = 0; 39 | 40 | virtual std::string get_r_type() const = 0; 41 | 42 | bool is_same_typeid(SubsetVectorVisitor* other) const { 43 | return typeid(*other) == typeid(*this); 44 | } 45 | 46 | virtual bool is_same_type(SubsetVectorVisitor* other, std::stringstream&, const SymbolString&) const { 47 | return is_same_typeid(other); 48 | } 49 | 50 | virtual bool is_compatible(SubsetVectorVisitor* other, std::stringstream&, const SymbolString&) const = 0; 51 | 52 | }; 53 | 54 | } // namespace dplyr 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /R/colwise-group-by.R: -------------------------------------------------------------------------------- 1 | #' Group by a selection of variables 2 | #' 3 | #' These [scoped] variants of [group_by()] group a data frame by a 4 | #' selection of variables. Like [group_by()], they have optional 5 | #' [mutate] semantics. 6 | #' 7 | #' @inheritParams scoped 8 | #' @param .add Passed to the `add` argument of [group_by()]. 9 | #' @export 10 | #' @examples 11 | #' # Group a data frame by all variables: 12 | #' group_by_all(mtcars) 13 | #' 14 | #' # Group by variables selected with a predicate: 15 | #' group_by_if(iris, is.factor) 16 | #' 17 | #' # Group by variables selected by name: 18 | #' group_by_at(mtcars, vars(vs, am)) 19 | #' 20 | #' # Like group_by(), the scoped variants have optional mutate 21 | #' # semantics. This provide a shortcut for group_by() + mutate(): 22 | #' group_by_all(mtcars, as.factor) 23 | #' group_by_if(iris, is.factor, as.character) 24 | group_by_all <- function(.tbl, .funs = list(), ...) { 25 | funs <- manip_all(.tbl, .funs, enquo(.funs), caller_env(), ...) 26 | if (!length(funs)) { 27 | funs <- syms(tbl_vars(.tbl)) 28 | } 29 | group_by(.tbl, !!! funs) 30 | } 31 | #' @rdname group_by_all 32 | #' @export 33 | group_by_at <- function(.tbl, .vars, .funs = list(), ..., .add = FALSE) { 34 | funs <- manip_at(.tbl, .vars, .funs, enquo(.funs), caller_env(), ...) 35 | if (!length(funs)) { 36 | funs <- tbl_at_syms(.tbl, .vars) 37 | } 38 | group_by(.tbl, !!! funs, add = .add) 39 | } 40 | #' @rdname group_by_all 41 | #' @export 42 | group_by_if <- function(.tbl, .predicate, .funs = list(), ..., .add = FALSE) { 43 | funs <- manip_if(.tbl, .predicate, .funs, enquo(.funs), caller_env(), ...) 44 | if (!length(funs)) { 45 | funs <- tbl_if_syms(.tbl, .predicate) 46 | } 47 | group_by(.tbl, !!! funs, add = .add) 48 | } 49 | --------------------------------------------------------------------------------