├── .Rbuildignore
├── .github
├── .gitignore
├── CODEOWNERS
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE.md
├── SUPPORT.md
├── lock.yml
├── move.yml
└── workflows
│ ├── R-CMD-check.yaml
│ ├── pkgdown.yaml
│ ├── pr-commands.yaml
│ └── test-coverage.yaml
├── .gitignore
├── .vscode
├── extensions.json
├── launch.json
└── settings.json
├── DESCRIPTION
├── Doxyfile
├── LICENSE
├── LICENSE.md
├── NAMESPACE
├── NEWS.md
├── R
├── across.R
├── all-equal.R
├── arrange.R
├── bind-cols.R
├── bind-rows.R
├── by.R
├── case-match.R
├── case-when.R
├── coalesce.R
├── colwise-arrange.R
├── colwise-distinct.R
├── colwise-filter.R
├── colwise-funs.R
├── colwise-group-by.R
├── colwise-mutate.R
├── colwise-select.R
├── colwise.R
├── compat-dbplyr.R
├── compat-name-repair.R
├── compute-collect.R
├── conditions.R
├── consecutive-id.R
├── context.R
├── copy-to.R
├── count-tally.R
├── data-bands.R
├── data-mask.R
├── data-starwars.R
├── data-storms.R
├── dbplyr.R
├── defunct.R
├── deprec-combine.R
├── deprec-context.R
├── deprec-dbi.R
├── deprec-do.R
├── deprec-funs.R
├── deprec-lazyeval.R
├── deprec-src-local.R
├── deprec-tibble.R
├── desc.R
├── distinct.R
├── doc-methods.R
├── doc-params.R
├── dplyr.R
├── error.R
├── explain.R
├── filter.R
├── funs.R
├── generics.R
├── group-by.R
├── group-data.R
├── group-map.R
├── group-nest.R
├── group-split.R
├── group-trim.R
├── grouped-df.R
├── groups-with.R
├── if-else.R
├── import-standalone-lazyeval.R
├── import-standalone-obj-type.R
├── import-standalone-purrr.R
├── import-standalone-types-check.R
├── join-by.R
├── join-cols.R
├── join-common-by.R
├── join-cross.R
├── join-rows.R
├── join.R
├── lead-lag.R
├── locale.R
├── mutate.R
├── n-col.R
├── n-distinct.R
├── na-if.R
├── near.R
├── nest-by.R
├── nth-value.R
├── order-by.R
├── pick.R
├── progress.R
├── pull.R
├── rank.R
├── recode.R
├── reexport-magrittr.R
├── reexport-pillar.R
├── reexport-tibble.R
├── reframe.R
├── relocate.R
├── rename.R
├── rows.R
├── rowwise.R
├── sample.R
├── select-helpers.R
├── select.R
├── sets.R
├── slice.R
├── src-dbi.R
├── src.R
├── summarise.R
├── tbl.R
├── top-n.R
├── transmute.R
├── ts.R
├── utils-format.R
├── utils-tidy-eval.R
├── utils.R
├── vctrs.R
├── vec-case-match.R
├── vec-case-when.R
└── zzz.R
├── README.Rmd
├── README.md
├── _pkgdown.yml
├── air.toml
├── codecov.yml
├── cran-comments.md
├── data-raw
├── band_members.R
├── starwars.R
├── starwars.csv
├── storms.R
└── storms.csv
├── data
├── band_instruments.rda
├── band_instruments2.rda
├── band_members.rda
├── starwars.rda
└── storms.rda
├── dplyr.Rproj
├── inst
├── bench
│ ├── bench-mean.R
│ └── bench.R
└── db
│ └── .gitignore
├── man
├── across.Rd
├── add_rownames.Rd
├── all_equal.Rd
├── all_vars.Rd
├── args_by.Rd
├── arrange.Rd
├── arrange_all.Rd
├── auto_copy.Rd
├── backend_dbplyr.Rd
├── band_members.Rd
├── between.Rd
├── bind_cols.Rd
├── bind_rows.Rd
├── c_across.Rd
├── case_match.Rd
├── case_when.Rd
├── check_dbplyr.Rd
├── coalesce.Rd
├── combine.Rd
├── common_by.Rd
├── compute.Rd
├── consecutive_id.Rd
├── context.Rd
├── copy_to.Rd
├── count.Rd
├── cross_join.Rd
├── cumall.Rd
├── defunct.Rd
├── deprec-context.Rd
├── desc.Rd
├── dim_desc.Rd
├── distinct.Rd
├── distinct_all.Rd
├── do.Rd
├── dplyr-locale.Rd
├── dplyr-package.Rd
├── dplyr_by.Rd
├── dplyr_data_masking.Rd
├── dplyr_extending.Rd
├── dplyr_tidy_select.Rd
├── explain.Rd
├── figures
│ ├── lifecycle-archived.svg
│ ├── lifecycle-defunct.svg
│ ├── lifecycle-deprecated.svg
│ ├── lifecycle-experimental.svg
│ ├── lifecycle-maturing.svg
│ ├── lifecycle-questioning.svg
│ ├── lifecycle-retired.svg
│ ├── lifecycle-soft-deprecated.svg
│ ├── lifecycle-stable.svg
│ ├── lifecycle-superseded.svg
│ └── logo.png
├── filter-joins.Rd
├── filter.Rd
├── filter_all.Rd
├── funs.Rd
├── glimpse.Rd
├── group_by.Rd
├── group_by_all.Rd
├── group_by_drop_default.Rd
├── group_by_prepare.Rd
├── group_cols.Rd
├── group_data.Rd
├── group_map.Rd
├── group_nest.Rd
├── group_split.Rd
├── group_trim.Rd
├── grouped_df.Rd
├── ident.Rd
├── if_else.Rd
├── join_by.Rd
├── last_dplyr_warnings.Rd
├── lead-lag.Rd
├── make_tbl.Rd
├── mutate-joins.Rd
├── mutate.Rd
├── mutate_all.Rd
├── n_distinct.Rd
├── na_if.Rd
├── near.Rd
├── nest_by.Rd
├── nest_join.Rd
├── new_grouped_df.Rd
├── nth.Rd
├── ntile.Rd
├── order_by.Rd
├── percent_rank.Rd
├── pick.Rd
├── progress_estimated.Rd
├── pull.Rd
├── recode.Rd
├── reexports.Rd
├── reframe.Rd
├── relocate.Rd
├── rename.Rd
├── rmd
│ ├── by.Rmd
│ ├── overview.Rmd
│ └── select.Rmd
├── row_number.Rd
├── rows.Rd
├── rowwise.Rd
├── same_src.Rd
├── sample_n.Rd
├── scoped.Rd
├── se-deprecated.Rd
├── select.Rd
├── select_all.Rd
├── setops.Rd
├── slice.Rd
├── sql.Rd
├── src.Rd
├── src_dbi.Rd
├── src_local.Rd
├── src_tbls.Rd
├── starwars.Rd
├── storms.Rd
├── summarise.Rd
├── summarise_all.Rd
├── summarise_each.Rd
├── tbl.Rd
├── tbl_df.Rd
├── tbl_ptype.Rd
├── tbl_vars.Rd
├── tidyeval-compat.Rd
├── top_n.Rd
├── transmute.Rd
├── vars.Rd
├── with_groups.Rd
└── with_order.Rd
├── pkgdown
└── favicon
│ ├── apple-touch-icon-120x120.png
│ ├── apple-touch-icon-152x152.png
│ ├── apple-touch-icon-180x180.png
│ ├── apple-touch-icon-60x60.png
│ ├── apple-touch-icon-76x76.png
│ ├── apple-touch-icon.png
│ ├── favicon-16x16.png
│ ├── favicon-32x32.png
│ └── favicon.ico
├── revdep
├── .gitignore
├── README.md
├── check.R
├── cran.md
├── drake-analyze.R
├── drake-base.R
├── drake-deps.R
├── drake.R
├── email.md
├── email.yml
├── failures.md
├── new-problems.md
├── problems.md
└── revdep_dplyr_1.0.0.md
├── src
├── chop.cpp
├── dplyr.h
├── filter.cpp
├── funs.cpp
├── group_by.cpp
├── group_data.cpp
├── imports.cpp
├── init.cpp
├── mask.cpp
├── mutate.cpp
├── reconstruct.cpp
├── slice.cpp
└── summarise.cpp
├── tests
├── testthat.R
└── testthat
│ ├── .gitignore
│ ├── _snaps
│ ├── across.md
│ ├── all-equal.md
│ ├── arrange.md
│ ├── bind-cols.md
│ ├── bind-rows.md
│ ├── by.md
│ ├── case-match.md
│ ├── case-when.md
│ ├── coalesce.md
│ ├── colwise-filter.md
│ ├── colwise-mutate.md
│ ├── colwise-select.md
│ ├── colwise.md
│ ├── conditions.md
│ ├── consecutive-id.md
│ ├── context.md
│ ├── copy-to.md
│ ├── count-tally.md
│ ├── defunct.md
│ ├── deprec-combine.md
│ ├── deprec-context.md
│ ├── deprec-dbi.md
│ ├── deprec-do.md
│ ├── deprec-funs.md
│ ├── deprec-lazyeval.md
│ ├── deprec-src-local.md
│ ├── desc.md
│ ├── distinct.md
│ ├── filter.md
│ ├── funs.md
│ ├── group-by.md
│ ├── group-map.md
│ ├── grouped-df.md
│ ├── if-else.md
│ ├── join-by.md
│ ├── join-cols.md
│ ├── join-cross.md
│ ├── join-rows.md
│ ├── join.md
│ ├── lead-lag.md
│ ├── locale.md
│ ├── mutate.md
│ ├── n-distinct.md
│ ├── na-if.md
│ ├── nth-value.md
│ ├── order-by.md
│ ├── pick.md
│ ├── rank.md
│ ├── recode.md
│ ├── reframe.md
│ ├── relocate.md
│ ├── rename.md
│ ├── rows.md
│ ├── rowwise.md
│ ├── sample.md
│ ├── select.md
│ ├── sets.md
│ ├── slice.md
│ ├── summarise.md
│ ├── top-n.md
│ ├── transmute.md
│ ├── vec-case-match.md
│ └── vec-case-when.md
│ ├── helper-dplyr.R
│ ├── helper-encoding.R
│ ├── helper-lazy.R
│ ├── helper-pick.R
│ ├── helper-s3.R
│ ├── helper-torture.R
│ ├── test-across.R
│ ├── test-all-equal.R
│ ├── test-arrange.R
│ ├── test-bind-cols.R
│ ├── test-bind-rows.R
│ ├── test-by.R
│ ├── test-case-match.R
│ ├── test-case-when.R
│ ├── test-coalesce.R
│ ├── test-colwise-arrange.R
│ ├── test-colwise-distinct.R
│ ├── test-colwise-filter.R
│ ├── test-colwise-funs.R
│ ├── test-colwise-group-by.R
│ ├── test-colwise-mutate.R
│ ├── test-colwise-select.R
│ ├── test-colwise.R
│ ├── test-conditions.R
│ ├── test-consecutive-id.R
│ ├── test-context.R
│ ├── test-copy-to.R
│ ├── test-count-tally.R
│ ├── test-data-mask.R
│ ├── test-defunct.R
│ ├── test-deprec-combine.R
│ ├── test-deprec-context.R
│ ├── test-deprec-dbi.R
│ ├── test-deprec-do.R
│ ├── test-deprec-funs.R
│ ├── test-deprec-lazyeval.R
│ ├── test-deprec-src-local.R
│ ├── test-deprec-tibble.R
│ ├── test-desc.R
│ ├── test-distinct.R
│ ├── test-filter.R
│ ├── test-funs.R
│ ├── test-generics.R
│ ├── test-group-by.R
│ ├── test-group-data.R
│ ├── test-group-map.R
│ ├── test-group-nest.R
│ ├── test-group-split.R
│ ├── test-group-trim.R
│ ├── test-grouped-df.R
│ ├── test-groups-with.R
│ ├── test-if-else.R
│ ├── test-join-by.R
│ ├── test-join-cols.R
│ ├── test-join-cross.R
│ ├── test-join-rows.R
│ ├── test-join.R
│ ├── test-lead-lag.R
│ ├── test-locale.R
│ ├── test-mutate.R
│ ├── test-n-distinct.R
│ ├── test-na-if.R
│ ├── test-near.R
│ ├── test-nest-by.R
│ ├── test-nth-value.R
│ ├── test-order-by.R
│ ├── test-pick.R
│ ├── test-pull.R
│ ├── test-rank.R
│ ├── test-recode.R
│ ├── test-reframe.R
│ ├── test-relocate.R
│ ├── test-rename.R
│ ├── test-rows.R
│ ├── test-rowwise.R
│ ├── test-sample.R
│ ├── test-select-helpers.R
│ ├── test-select.R
│ ├── test-sets.R
│ ├── test-slice.R
│ ├── test-src-dbi.R
│ ├── test-summarise.R
│ ├── test-tbl.R
│ ├── test-top-n.R
│ ├── test-transmute.R
│ ├── test-utils.R
│ ├── test-vec-case-match.R
│ ├── test-vec-case-when.R
│ └── utf-8.txt
└── vignettes
├── .gitignore
├── base.Rmd
├── colwise.Rmd
├── dplyr.Rmd
├── grouping.Rmd
├── in-packages.Rmd
├── programming.Rmd
├── rowwise.Rmd
├── two-table.Rmd
└── window-functions.Rmd
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^pkgdown$
2 | ^.*\.Rproj$
3 | ^\.Rproj\.user$
4 | ^\.travis\.yml$
5 | ^.Rprofile$
6 | ^inst/db$
7 | ^inst/bench$
8 | ^man-roxygen$
9 | ^demo/pandas$
10 | ^\.httr-oauth$
11 | ^cran-comments\.md$
12 | ^README\.Rmd$
13 | ^revdep$
14 | ^README-.*\.png$
15 | ^codecov\.yml$
16 | ^appveyor\.yml$
17 | ^Doxyfile$
18 | ^clion-test\.R$
19 | ^API$
20 | ^ISSUE_TEMPLATE\.md$
21 | ^data-raw$
22 | ^LICENSE\.md$
23 | ^BROWSE$
24 | ^GPATH$
25 | ^GRTAGS$
26 | ^GTAGS$
27 | ^TAGS$
28 | ^\.dir-locals\.el$
29 | ^vignettes/rsconnect$
30 | ^docs$
31 | ^_pkgdown\.yml$
32 | ^issues$
33 | ^CONDUCT\.md$
34 | ^\.drake$
35 | ^CRAN-RELEASE$
36 | ^\.github$
37 | ^\.github/workflows/R-CMD-check\.yaml$
38 | ^\.github/workflows/pr-commands\.yaml$
39 | ^\.github/workflows/pkgdown\.yaml$
40 | ^doc$
41 | ^Meta$
42 | ^CRAN-SUBMISSION$
43 | ^compile_commands\.json$
44 | ^\.cache$
45 | ^\.vscode$
46 | ^[\.]?air\.toml$
47 |
--------------------------------------------------------------------------------
/.github/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # https://www.tidyverse.org/development/understudies
2 | .github/CODEOWNERS @hadley @romainfrancois @krlmlr
3 |
--------------------------------------------------------------------------------
/.github/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. Instead, ask on or .
2 |
3 | Please include a minimal reproducible example (AKA a reprex). If you've never heard of a [reprex](http://reprex.tidyverse.org/) before, start by reading .
4 |
5 | ---
6 |
7 | Brief description of the problem
8 |
9 | ```r
10 | # insert reprex here
11 | ```
12 |
--------------------------------------------------------------------------------
/.github/SUPPORT.md:
--------------------------------------------------------------------------------
1 | # Getting help with dplyr
2 |
3 | Thanks for using dplyr. Before filing an issue, there are a few places
4 | to explore and pieces to put together to make the process as smooth as possible.
5 |
6 | Start by making a minimal **repr**oducible **ex**ample using the
7 | [reprex](http://reprex.tidyverse.org/) package. If you haven't heard of or used
8 | reprex before, you're in for a treat! Seriously, reprex will make all of your
9 | R-question-asking endeavors easier (which is a pretty insane ROI for the five to
10 | ten minutes it'll take you to learn what it's all about). For additional reprex
11 | pointers, check out the [Get help!](https://www.tidyverse.org/help/) section of
12 | the tidyverse site.
13 |
14 | Armed with your reprex, the next step is to figure out [where to ask](https://www.tidyverse.org/help/#where-to-ask).
15 |
16 | * If it's a question: start with [community.rstudio.com](https://community.rstudio.com/),
17 | and/or StackOverflow. There are more people there to answer questions.
18 | * If it's a bug: you're in the right place, file an issue.
19 | * If you're not sure: let the community help you figure it out! If your
20 | problem _is_ a bug or a feature request, you can easily return here and
21 | report it.
22 |
23 | Before opening a new issue, be sure to [search issues and pull requests](https://github.com/tidyverse/dplyr/issues) to make sure the
24 | bug hasn't been reported and/or already fixed in the development version. By
25 | default, the search will be pre-populated with `is:issue is:open`. You can
26 | [edit the qualifiers](https://help.github.com/articles/searching-issues-and-pull-requests/)
27 | (e.g. `is:pr`, `is:closed`) as needed. For example, you'd simply
28 | remove `is:open` to search _all_ issues in the repo, open or closed.
29 |
30 |
31 | If you _are_ in the right place, and need to file an issue, please review the
32 | ["File issues"](https://www.tidyverse.org/contribute/#issues) paragraph from
33 | the tidyverse contributing guidelines.
34 |
35 | Thanks for your help!
36 |
--------------------------------------------------------------------------------
/.github/lock.yml:
--------------------------------------------------------------------------------
1 | # Configuration for lock-threads - https://github.com/dessant/lock-threads
2 |
3 | # Number of days of inactivity before a closed issue or pull request is locked
4 | daysUntilLock: 180
5 |
6 | # Issues and pull requests with these labels will not be locked. Set to `[]` to disable
7 | exemptLabels: []
8 |
9 | # Label to add before locking, such as `outdated`. Set to `false` to disable
10 | lockLabel: false
11 |
12 | # Stop lockbot from closing as "resolved"
13 | setLockReason: false
14 |
15 | # Comment to post before locking. Set to `false` to disable
16 | lockComment: >
17 | This old issue has been automatically locked. If you believe you
18 | have found a related problem, please file a new issue (with reprex)
19 | and link to this issue.
20 |
21 | # Limit to only `issues` or `pulls`
22 | # only: issues
23 |
24 | # Optionally, specify configuration settings just for `issues` or `pulls`
25 | # issues:
26 | # exemptLabels:
27 | # - help-wanted
28 | # lockLabel: outdated
29 |
30 | # pulls:
31 | # daysUntilLock: 30
32 |
--------------------------------------------------------------------------------
/.github/move.yml:
--------------------------------------------------------------------------------
1 | # Configuration for move-issues bot - https://github.com/dessant/move-issues
2 |
3 | # Delete the command comment when it contains no other content
4 | deleteCommand: true
5 |
6 | # Close the source issue after moving
7 | closeSourceIssue: true
8 |
9 | # Lock the source issue after moving
10 | lockSourceIssue: false
11 |
12 | # Mention issue and comment authors
13 | mentionAuthors: true
14 |
15 | # Preserve mentions in the issue content
16 | keepContentMentions: true
17 |
18 | # Set custom aliases for targets
19 | # aliases:
20 | # r: repo
21 | # or: owner/repo
22 |
--------------------------------------------------------------------------------
/.github/workflows/pkgdown.yaml:
--------------------------------------------------------------------------------
1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3 | on:
4 | push:
5 | branches: [main, master]
6 | pull_request:
7 | branches: [main, master]
8 | release:
9 | types: [published]
10 | workflow_dispatch:
11 |
12 | name: pkgdown.yaml
13 |
14 | permissions: read-all
15 |
16 | jobs:
17 | pkgdown:
18 | runs-on: ubuntu-latest
19 | # Only restrict concurrency for non-PR jobs
20 | concurrency:
21 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
22 | env:
23 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
24 | permissions:
25 | contents: write
26 | steps:
27 | - uses: actions/checkout@v4
28 |
29 | - uses: r-lib/actions/setup-pandoc@v2
30 |
31 | - uses: r-lib/actions/setup-r@v2
32 | with:
33 | use-public-rspm: true
34 |
35 | - uses: r-lib/actions/setup-r-dependencies@v2
36 | with:
37 | extra-packages: any::pkgdown, local::.
38 | needs: website
39 |
40 | - name: Build site
41 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
42 | shell: Rscript {0}
43 |
44 | - name: Deploy to GitHub pages 🚀
45 | if: github.event_name != 'pull_request'
46 | uses: JamesIves/github-pages-deploy-action@v4.5.0
47 | with:
48 | clean: false
49 | branch: gh-pages
50 | folder: docs
51 |
--------------------------------------------------------------------------------
/.github/workflows/test-coverage.yaml:
--------------------------------------------------------------------------------
1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3 | on:
4 | push:
5 | branches: [main, master]
6 | pull_request:
7 | branches: [main, master]
8 |
9 | name: test-coverage.yaml
10 |
11 | permissions: read-all
12 |
13 | jobs:
14 | test-coverage:
15 | runs-on: ubuntu-latest
16 | env:
17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
18 |
19 | steps:
20 | - uses: actions/checkout@v4
21 |
22 | - uses: r-lib/actions/setup-r@v2
23 | with:
24 | use-public-rspm: true
25 |
26 | - uses: r-lib/actions/setup-r-dependencies@v2
27 | with:
28 | extra-packages: any::covr, any::xml2
29 | needs: coverage
30 |
31 | - name: Test coverage
32 | run: |
33 | cov <- covr::package_coverage(
34 | quiet = FALSE,
35 | clean = FALSE,
36 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
37 | )
38 | covr::to_cobertura(cov)
39 | shell: Rscript {0}
40 |
41 | - uses: codecov/codecov-action@v4
42 | with:
43 | fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
44 | file: ./cobertura.xml
45 | plugin: noop
46 | disable_search: true
47 | token: ${{ secrets.CODECOV_TOKEN }}
48 |
49 | - name: Show testthat output
50 | if: always()
51 | run: |
52 | ## --------------------------------------------------------------------
53 | find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
54 | shell: bash
55 |
56 | - name: Upload test results
57 | if: failure()
58 | uses: actions/upload-artifact@v4
59 | with:
60 | name: coverage-test-failures
61 | path: ${{ runner.temp }}/package
62 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | docs
2 | /src/*.o
3 | /src/*.o-*
4 | /src/*.d
5 | /src/*.so
6 | *.dll
7 | .RData
8 | .Rproj.user
9 | .Rhistory
10 | inst/doc
11 | .httr-oauth
12 | vignettes/*.R
13 | .DS_Store
14 | /clion-test.R
15 | /BROWSE
16 | /GPATH
17 | /GRTAGS
18 | /GTAGS
19 | /TAGS
20 | /.dir-locals.el
21 | /issues
22 | /.drake
23 | bench-libs
24 | doc
25 | Meta
26 | compile_commands.json
27 | .cache
28 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "Posit.air-vscode"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | "name": "(lldb) Attach to R",
6 | "type": "lldb",
7 | "request": "attach",
8 | "pid": "${command:pickMyProcess}",
9 | "stopOnEntry": false
10 | }
11 | ]
12 | }
13 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "[r]": {
3 | "editor.formatOnSave": true,
4 | "editor.defaultFormatter": "Posit.air-vscode"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Type: Package
2 | Package: dplyr
3 | Title: A Grammar of Data Manipulation
4 | Version: 1.1.4.9000
5 | Authors@R: c(
6 | person("Hadley", "Wickham", , "hadley@posit.co", role = c("aut", "cre"),
7 | comment = c(ORCID = "0000-0003-4757-117X")),
8 | person("Romain", "François", role = "aut",
9 | comment = c(ORCID = "0000-0002-2444-4226")),
10 | person("Lionel", "Henry", role = "aut"),
11 | person("Kirill", "Müller", role = "aut",
12 | comment = c(ORCID = "0000-0002-1416-3412")),
13 | person("Davis", "Vaughan", , "davis@posit.co", role = "aut",
14 | comment = c(ORCID = "0000-0003-4777-038X")),
15 | person("Posit Software, PBC", role = c("cph", "fnd"))
16 | )
17 | Description: A fast, consistent tool for working with data frame like
18 | objects, both in memory and out of memory.
19 | License: MIT + file LICENSE
20 | URL: https://dplyr.tidyverse.org, https://github.com/tidyverse/dplyr
21 | BugReports: https://github.com/tidyverse/dplyr/issues
22 | Depends:
23 | R (>= 3.6.0)
24 | Imports:
25 | cli (>= 3.6.2),
26 | generics,
27 | glue (>= 1.3.2),
28 | lifecycle (>= 1.0.3),
29 | magrittr (>= 1.5),
30 | methods,
31 | pillar (>= 1.9.0),
32 | R6,
33 | rlang (>= 1.1.3),
34 | tibble (>= 3.2.0),
35 | tidyselect (>= 1.2.0),
36 | utils,
37 | vctrs (>= 0.6.4)
38 | Suggests:
39 | bench,
40 | broom,
41 | callr,
42 | covr,
43 | DBI,
44 | dbplyr (>= 2.2.1),
45 | ggplot2,
46 | knitr,
47 | Lahman,
48 | lobstr,
49 | microbenchmark,
50 | nycflights13,
51 | purrr,
52 | rmarkdown,
53 | RMySQL,
54 | RPostgreSQL,
55 | RSQLite,
56 | stringi (>= 1.7.6),
57 | testthat (>= 3.1.5),
58 | tidyr (>= 1.3.0),
59 | withr
60 | VignetteBuilder:
61 | knitr
62 | Config/Needs/website: tidyverse, shiny, pkgdown, tidyverse/tidytemplate
63 | Config/testthat/edition: 3
64 | Config/build/compilation-database: true
65 | Encoding: UTF-8
66 | LazyData: true
67 | Roxygen: list(markdown = TRUE)
68 | RoxygenNote: 7.3.2
69 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | YEAR: 2023
2 | COPYRIGHT HOLDER: dplyr authors
3 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # MIT License
2 |
3 | Copyright (c) 2023 dplyr authors
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/R/bind-cols.R:
--------------------------------------------------------------------------------
1 | #' Bind multiple data frames by column
2 | #'
3 | #' @description
4 | #' Bind any number of data frames by column, making a wider result.
5 | #' This is similar to `do.call(cbind, dfs)`.
6 | #'
7 | #' Where possible prefer using a [join][left_join] to combine multiple
8 | #' data frames. `bind_cols()` binds the rows in order in which they appear
9 | #' so it is easy to create meaningless results without realising it.
10 | #'
11 | #' @param ... Data frames to combine. Each argument can either be a data frame,
12 | #' a list that could be a data frame, or a list of data frames.
13 | #' Inputs are [recycled][vctrs::theory-faq-recycling] to the same length,
14 | #' then matched by position.
15 | #' @param .name_repair One of `"unique"`, `"universal"`, or
16 | #' `"check_unique"`. See [vctrs::vec_as_names()] for the meaning of these
17 | #' options.
18 | #' @returns A data frame the same type as the first element of `...`.
19 | #' @export
20 | #' @examples
21 | #' df1 <- tibble(x = 1:3)
22 | #' df2 <- tibble(y = 3:1)
23 | #' bind_cols(df1, df2)
24 | #'
25 | #' # Row sizes must be compatible when column-binding
26 | #' try(bind_cols(tibble(x = 1:3), tibble(y = 1:2)))
27 | bind_cols <- function(
28 | ...,
29 | .name_repair = c("unique", "universal", "check_unique", "minimal")
30 | ) {
31 | dots <- list2(...)
32 |
33 | dots <- list_flatten(dots, recursive = TRUE)
34 | dots <- discard(dots, is.null)
35 |
36 | # Strip names off of data frame components so that vec_cbind() unpacks them
37 | names2(dots)[map_lgl(dots, is.data.frame)] <- ""
38 |
39 | out <- vec_cbind(
40 | !!!dots,
41 | .name_repair = .name_repair,
42 | .error_call = current_env()
43 | )
44 | if (!any(map_lgl(dots, is.data.frame))) {
45 | out <- as_tibble(out)
46 | }
47 | if (length(dots) && is.data.frame(first <- dots[[1L]])) {
48 | out <- dplyr_reconstruct(out, first)
49 | }
50 | out
51 | }
52 |
--------------------------------------------------------------------------------
/R/consecutive-id.R:
--------------------------------------------------------------------------------
1 | #' Generate a unique identifier for consecutive combinations
2 | #'
3 | #' `consecutive_id()` generates a unique identifier that increments every time
4 | #' a variable (or combination of variables) changes. Inspired by
5 | #' `data.table::rleid()`.
6 | #'
7 | #' @inheritParams n_distinct
8 | #' @returns A numeric vector the same length as the longest
9 | #' element of `...`.
10 | #' @export
11 | #' @examples
12 | #' consecutive_id(c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, NA, NA))
13 | #' consecutive_id(c(1, 1, 1, 2, 1, 1, 2, 2))
14 | #'
15 | #' df <- data.frame(x = c(0, 0, 1, 0), y = c(2, 2, 2, 2))
16 | #' df %>% group_by(x, y) %>% summarise(n = n())
17 | #' df %>% group_by(id = consecutive_id(x, y), x, y) %>% summarise(n = n())
18 | consecutive_id <- function(...) {
19 | check_dots_unnamed()
20 |
21 | data <- df_list(
22 | ...,
23 | .unpack = FALSE,
24 | .name_repair = "minimal",
25 | .error_call = current_env()
26 | )
27 | data <- new_data_frame(data)
28 |
29 | out <- vec_identify_runs(data)
30 | attr(out, "n") <- NULL
31 |
32 | out
33 | }
34 |
--------------------------------------------------------------------------------
/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 | #' @format NULL
21 | "band_instruments"
22 |
23 | #' @rdname band_members
24 | #' @format NULL
25 | "band_instruments2"
26 |
--------------------------------------------------------------------------------
/R/data-starwars.R:
--------------------------------------------------------------------------------
1 | #' Starwars characters
2 | #'
3 | #' The original data, from SWAPI, the Star Wars API, , has been revised
4 | #' to reflect additional research into gender and sex determinations of characters.
5 | #'
6 | #' @format A tibble with 87 rows and 14 variables:
7 | #' \describe{
8 | #' \item{name}{Name of the character}
9 | #' \item{height}{Height (cm)}
10 | #' \item{mass}{Weight (kg)}
11 | #' \item{hair_color,skin_color,eye_color}{Hair, skin, and eye colors}
12 | #' \item{birth_year}{Year born (BBY = Before Battle of Yavin)}
13 | #' \item{sex}{The biological sex of the character, namely male, female, hermaphroditic, or none (as in the case for Droids).}
14 | #' \item{gender}{The gender role or gender identity of the character as determined by their personality or the way they were programmed (as in the case for Droids).}
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 | #' @examples
22 | #' starwars
23 | "starwars"
24 |
--------------------------------------------------------------------------------
/R/deprec-combine.R:
--------------------------------------------------------------------------------
1 | #' Combine vectors
2 | #'
3 | #' @description
4 | #' `r lifecycle::badge("deprecated")`
5 | #'
6 | #' `combine()` is deprecated in favour of [vctrs::vec_c()]. `combine()`
7 | #' attempted to automatically guess whether you wanted [c()] or [unlist()],
8 | #' but could fail in surprising ways. We now believe it's better to be explicit.
9 | #'
10 | #' @param ... Vectors to combine.
11 | #' @keywords internal
12 | #' @export
13 | #' @examples
14 | #' f1 <- factor("a")
15 | #' f2 <- factor("b")
16 | #'
17 | #' combine(f1, f2)
18 | #' # ->
19 | #' vctrs::vec_c(f1, f1)
20 | #'
21 | #' combine(list(f1, f2))
22 | #' # ->
23 | #' vctrs::vec_c(!!!list(f1, f2))
24 | combine <- function(...) {
25 | lifecycle::deprecate_warn(
26 | "1.0.0",
27 | "combine()",
28 | "vctrs::vec_c()",
29 | always = TRUE
30 | )
31 |
32 | args <- list2(...)
33 | if (length(args) == 1 && is.list(args[[1]])) {
34 | args <- args[[1]]
35 | }
36 | args <- keep(args, function(.x) !is.null(.x))
37 | names(args) <- NULL
38 | if (length(args) == 0) {
39 | logical()
40 | } else {
41 | vec_c(!!!args)
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/R/deprec-context.R:
--------------------------------------------------------------------------------
1 | #' Information about the "current" group or variable
2 | #'
3 | #' @description
4 | #' `r lifecycle::badge("deprecated")`
5 | #'
6 | #' These functions were deprecated in dplyr 1.1.0.
7 | #'
8 | #' * `cur_data()` is deprecated in favor of [pick()].
9 | #' * `cur_data_all()` is deprecated but does not have a direct replacement as
10 | #' selecting the grouping variables is not well-defined and is unlikely to
11 | #' ever be useful.
12 | #'
13 | #' @keywords internal
14 | #' @name deprec-context
15 | NULL
16 |
17 | #' @rdname deprec-context
18 | #' @export
19 | cur_data <- function() {
20 | lifecycle::deprecate_soft(
21 | when = "1.1.0",
22 | what = "cur_data()",
23 | with = "pick()"
24 | )
25 | mask <- peek_mask()
26 | vars <- mask$current_non_group_vars()
27 | mask$pick_current(vars)
28 | }
29 |
30 | #' @rdname deprec-context
31 | #' @export
32 | cur_data_all <- function() {
33 | lifecycle::deprecate_soft(
34 | when = "1.1.0",
35 | what = "cur_data_all()",
36 | with = "pick()"
37 | )
38 | mask <- peek_mask()
39 | vars <- mask$current_vars()
40 | mask$pick_current(vars)
41 | }
42 |
--------------------------------------------------------------------------------
/R/deprec-tibble.R:
--------------------------------------------------------------------------------
1 | #' Coerce to a tibble
2 | #'
3 | #' `r lifecycle::badge("deprecated")`
4 | #' Please use [tibble::as_tibble()] instead.
5 | #'
6 | #' @export
7 | #' @keywords internal
8 | #' @param data,x Object to coerce
9 | tbl_df <- function(data) {
10 | lifecycle::deprecate_warn(
11 | "1.0.0",
12 | "tbl_df()",
13 | "tibble::as_tibble()",
14 | always = TRUE
15 | )
16 | # Works in tibble < 1.5.0 too, because .name_repair will be
17 | # swallowed by the ellipsis
18 | as_tibble(data, .name_repair = "check_unique")
19 | }
20 |
21 | #' @export
22 | #' @rdname tbl_df
23 | as.tbl <- function(x, ...) {
24 | lifecycle::deprecate_warn(
25 | "1.0.0",
26 | "as.tbl()",
27 | "tibble::as_tibble()",
28 | always = TRUE
29 | )
30 | UseMethod("as.tbl")
31 | }
32 |
33 | #' @export
34 | as.tbl.tbl <- function(x, ...) x
35 |
36 | #' @export
37 | as.tbl.data.frame <- function(x, ...) {
38 | as_tibble(x)
39 | }
40 |
41 | #' Convert row names to an explicit variable.
42 | #'
43 | #' `r lifecycle::badge("deprecated")`
44 | #' Please use [tibble::rownames_to_column()] instead.
45 | #'
46 | #' @param df Input data frame with rownames.
47 | #' @param var Name of variable to use
48 | #' @keywords internal
49 | #' @export
50 | add_rownames <- function(df, var = "rowname") {
51 | lifecycle::deprecate_warn(
52 | "1.0.0",
53 | "add_rownames()",
54 | "tibble::rownames_to_column()",
55 | always = TRUE
56 | )
57 |
58 | stopifnot(is.data.frame(df))
59 |
60 | rn <- as_tibble(setNames(list(rownames(df)), var))
61 | rownames(df) <- NULL
62 |
63 | bind_cols(rn, df)
64 | }
65 |
--------------------------------------------------------------------------------
/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) {
17 | obj_check_vector(x)
18 | -xtfrm(x)
19 | }
20 |
--------------------------------------------------------------------------------
/R/doc-params.R:
--------------------------------------------------------------------------------
1 | #' Argument type: tidy-select
2 | #'
3 | #' @description
4 | #' This page describes the `` argument modifier which indicates
5 | #' the argument supports **tidy selections**. Tidy selection provides a concise
6 | #' dialect of R for selecting variables based on their names or properties.
7 | #'
8 | #' Tidy selection is a variant of tidy evaluation. This means that inside
9 | #' functions, tidy-select arguments require special attention, as described in
10 | #' the *Indirection* section below. If you've never heard of tidy evaluation
11 | #' before, start with `vignette("programming")`.
12 | #'
13 | #'
14 | #' # Overview of selection features
15 | #'
16 | #' ```{r, child = "man/rmd/overview.Rmd"}
17 | #' ```
18 | #'
19 | #'
20 | #' # Indirection
21 | #'
22 | #' There are two main cases:
23 | #'
24 | #' * If you have a character vector of column names, use `all_of()`
25 | #' or `any_of()`, depending on whether or not you want unknown variable
26 | #' names to cause an error, e.g. `select(df, all_of(vars))`,
27 | #' `select(df, !any_of(vars))`.
28 | #'
29 | #' * If you want the user to be able to supply a tidyselect specification in
30 | #' a function argument, embrace the function argument, e.g.
31 | #' `select(df, {{ vars }})`.
32 | #'
33 | #' @keywords internal
34 | #' @name dplyr_tidy_select
35 | NULL
36 |
--------------------------------------------------------------------------------
/R/dplyr.R:
--------------------------------------------------------------------------------
1 | #' @description
2 | #' To learn more about dplyr, start with the vignettes:
3 | #' `browseVignettes(package = "dplyr")`
4 | #' @useDynLib dplyr, .registration = TRUE
5 | #' @keywords internal
6 | #' @import rlang
7 | #' @rawNamespace import(vctrs, except = data_frame)
8 | #' @importFrom glue glue glue_collapse glue_data
9 | #' @importFrom tibble new_tibble is_tibble
10 | #' @importFrom stats setNames update
11 | #' @importFrom utils head tail
12 | #' @importFrom methods setOldClass
13 | #' @importFrom lifecycle deprecated
14 | #' @importFrom R6 R6Class
15 | "_PACKAGE"
16 |
17 | # We're importing vctrs without `data_frame()` because we currently
18 | # reexport the deprecated `tibble::data_frame()` function
19 |
20 | on_load(local_use_cli())
21 |
22 | # Singletons
23 | the <- new_environment()
24 |
--------------------------------------------------------------------------------
/R/error.R:
--------------------------------------------------------------------------------
1 | # ngettext() does extra work, this function is a simpler version
2 | ntext <- function(n, msg1, msg2) {
3 | if (n == 1) msg1 else msg2
4 | }
5 |
6 | fmt_pos_args <- function(x) {
7 | args <- ntext(length(x), "Argument", "Arguments")
8 | glue("{args} {fmt_comma(x)}")
9 | }
10 |
11 | fmt_cols <- function(x) {
12 | cols <- ntext(length(x), "Column", "Columns")
13 | glue("{cols} {fmt_obj(x)}")
14 | }
15 |
16 | fmt_obj <- function(x) {
17 | fmt_comma(fmt_obj1(x))
18 | }
19 |
20 | fmt_obj1 <- function(x) {
21 | paste0("`", x, "`")
22 | }
23 |
24 | fmt_classes <- function(x) {
25 | paste(class(x), collapse = "/")
26 | }
27 |
28 | fmt_comma <- function(..., .max = 6) {
29 | x <- paste0(...)
30 | if (length(x) > .max) {
31 | length(x) <- .max
32 | x[[.max]] <- "..."
33 | }
34 |
35 | commas(x)
36 | }
37 |
--------------------------------------------------------------------------------
/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 | #' @examplesIf requireNamespace("dbplyr", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)
18 | #' \donttest{
19 | #' lahman_s <- dbplyr::lahman_sqlite()
20 | #' batting <- tbl(lahman_s, "Batting")
21 | #' batting %>% show_query()
22 | #' batting %>% explain()
23 | #'
24 | #' # The batting database has indices on all ID variables:
25 | #' # SQLite automatically picks the most restrictive index
26 | #' batting %>% filter(lgID == "NL" & yearID == 2000L) %>% explain()
27 | #'
28 | #' # OR's will use multiple indexes
29 | #' batting %>% filter(lgID == "NL" | yearID == 2000) %>% explain()
30 | #'
31 | #' # Joins will use indexes in both tables
32 | #' teams <- tbl(lahman_s, "Teams")
33 | #' batting %>% left_join(teams, c("yearID", "teamID")) %>% explain()
34 | #' }
35 | explain <- function(x, ...) {
36 | UseMethod("explain")
37 | }
38 |
39 | #' @export
40 | #' @rdname explain
41 | show_query <- function(x, ...) {
42 | UseMethod("show_query")
43 | }
44 |
--------------------------------------------------------------------------------
/R/group-trim.R:
--------------------------------------------------------------------------------
1 | #' Trim grouping structure
2 | #'
3 | #' @description
4 | #' `r lifecycle::badge("experimental")`
5 | #' Drop unused levels of all factors that are used as grouping variables,
6 | #' then recalculates the grouping structure.
7 | #'
8 | #' `group_trim()` is particularly useful after a [filter()] that is intended
9 | #' to select a subset of groups.
10 | #'
11 | #' @param .tbl A [grouped data frame][grouped_df()]
12 | #' @param .drop See [group_by()]
13 | #' @return A [grouped data frame][grouped_df()]
14 | #' @export
15 | #' @family grouping functions
16 | #' @examples
17 | #' iris %>%
18 | #' group_by(Species) %>%
19 | #' filter(Species == "setosa", .preserve = TRUE) %>%
20 | #' group_trim()
21 | group_trim <- function(.tbl, .drop = group_by_drop_default(.tbl)) {
22 | lifecycle::signal_stage("experimental", "group_trim()")
23 | UseMethod("group_trim")
24 | }
25 |
26 | #' @export
27 | group_trim.data.frame <- function(.tbl, .drop = group_by_drop_default(.tbl)) {
28 | .tbl
29 | }
30 |
31 | #' @export
32 | group_trim.grouped_df <- function(.tbl, .drop = group_by_drop_default(.tbl)) {
33 | vars <- group_vars(.tbl)
34 | ungrouped <- ungroup(.tbl)
35 |
36 | # names of the factors that should be droplevels()'d
37 | fgroups <- names(select_if(select_at(ungrouped, vars), is.factor))
38 |
39 | # drop levels
40 | dropped <- mutate_at(ungrouped, fgroups, droplevels)
41 |
42 | # regroup
43 | group_by_at(dropped, vars, .drop = .drop)
44 | }
45 |
--------------------------------------------------------------------------------
/R/groups-with.R:
--------------------------------------------------------------------------------
1 | #' Perform an operation with temporary groups
2 | #'
3 | #' @description
4 | #' `r lifecycle::badge("superseded")`
5 | #'
6 | #' This was an experimental function that allows you to modify the grouping
7 | #' variables for a single operation; it is superseded in favour of using the
8 | #' `.by` argument to individual verbs.
9 | #'
10 | #' @param .data A data frame
11 | #' @param .groups <[`tidy-select`][dplyr_tidy_select]> One or more variables
12 | #' to group by. Unlike [group_by()], you can only group by existing variables,
13 | #' and you can use tidy-select syntax like `c(x, y, z)` to select multiple
14 | #' variables.
15 | #'
16 | #' Use `NULL` to temporarily **un**group.
17 | #' @param .f Function to apply to regrouped data.
18 | #' Supports purrr-style `~` syntax
19 | #' @param ... Additional arguments passed on to `...`.
20 | #' @keywords internal
21 | #' @export
22 | #' @examples
23 | #' df <- tibble(g = c(1, 1, 2, 2, 3), x = runif(5))
24 | #'
25 | #' # Old
26 | #' df %>%
27 | #' with_groups(g, mutate, x_mean = mean(x))
28 | #' # New
29 | #' df %>% mutate(x_mean = mean(x), .by = g)
30 | with_groups <- function(.data, .groups, .f, ...) {
31 | lifecycle::signal_stage("experimental", "with_groups()")
32 | loc <- tidyselect::eval_select(enquo(.groups), data = tbl_ptype(.data))
33 | val <- syms(names(.data)[loc])
34 | out <- group_by(.data, !!!val)
35 |
36 | .f <- as_function(.f)
37 | out <- .f(out, ...)
38 | dplyr_reconstruct(out, .data)
39 | }
40 |
--------------------------------------------------------------------------------
/R/n-col.R:
--------------------------------------------------------------------------------
1 | # Masks `ncol()` to avoid accidentally materializing ALTREP duckplyr
2 | # data frames.
3 | ncol <- function(x) {
4 | abort("Use `df_n_col()` or `mat_n_col()` instead.")
5 | }
6 |
7 | # Alternative to `ncol()` which avoids `dim()`.
8 | #
9 | # `dim()` also requires knowing the number of rows,
10 | # which forces ALTREP duckplyr data frames to materialize.
11 | #
12 | # This function makes the same assertion as vctrs about data frame structure,
13 | # i.e. if `x` inherits from `"data.frame"`, then it is a VECSXP with length
14 | # equal to the number of columns.
15 | df_n_col <- function(x) {
16 | x <- unclass(x)
17 | obj_check_list(x)
18 | length(x)
19 | }
20 |
21 | # In a few places we call `ncol()` on matrices, and in those
22 | # cases we want to continue using the base version.
23 | mat_n_col <- function(x) {
24 | base::ncol(x)
25 | }
26 |
--------------------------------------------------------------------------------
/R/n-distinct.R:
--------------------------------------------------------------------------------
1 | #' Count unique combinations
2 | #'
3 | #' `n_distinct()` counts the number of unique/distinct combinations in a set
4 | #' of one or more vectors. It's a faster and more concise equivalent to
5 | #' `nrow(unique(data.frame(...)))`.
6 | #'
7 | #' @param ... Unnamed vectors. If multiple vectors are supplied, then they should
8 | #' have the same length.
9 | #' @param na.rm If `TRUE`, exclude missing observations from the count.
10 | #' If there are multiple vectors in `...`, an observation will
11 | #' be excluded if _any_ of the values are missing.
12 | #' @returns A single number.
13 | #' @export
14 | #' @examples
15 | #' x <- c(1, 1, 2, 2, 2)
16 | #' n_distinct(x)
17 | #'
18 | #' y <- c(3, 3, NA, 3, 3)
19 | #' n_distinct(y)
20 | #' n_distinct(y, na.rm = TRUE)
21 | #'
22 | #' # Pairs (1, 3), (2, 3), and (2, NA) are distinct
23 | #' n_distinct(x, y)
24 | #'
25 | #' # (2, NA) is dropped, leaving 2 distinct combinations
26 | #' n_distinct(x, y, na.rm = TRUE)
27 | #'
28 | #' # Also works with data frames
29 | #' n_distinct(data.frame(x, y))
30 | n_distinct <- function(..., na.rm = FALSE) {
31 | if (missing(...)) {
32 | cli::cli_abort("{.arg ...} is absent, but must be supplied.")
33 | }
34 | check_dots_unnamed()
35 |
36 | data <- df_list(
37 | ...,
38 | .unpack = FALSE,
39 | .name_repair = "minimal",
40 | .error_call = current_env()
41 | )
42 | data <- new_data_frame(data)
43 |
44 | if (isTRUE(na.rm)) {
45 | # Drop observation if *any* missing
46 | complete <- vec_detect_complete(data)
47 | data <- vec_slice(data, complete)
48 | }
49 |
50 | vec_unique_count(data)
51 | }
52 |
--------------------------------------------------------------------------------
/R/na-if.R:
--------------------------------------------------------------------------------
1 | #' Convert values to `NA`
2 | #'
3 | #' This is a translation of the SQL command `NULLIF`. It is useful if you want
4 | #' to convert an annoying value to `NA`.
5 | #'
6 | #' @param x Vector to modify
7 | #' @param y Value or vector to compare against. When `x` and `y` are equal, the
8 | #' value in `x` will be replaced with `NA`.
9 | #'
10 | #' `y` is [cast][vctrs::theory-faq-coercion] to the type of `x` before
11 | #' comparison.
12 | #'
13 | #' `y` is [recycled][vctrs::theory-faq-recycling] to the size of `x` before
14 | #' comparison. This means that `y` can be a vector with the same size as `x`,
15 | #' but most of the time this will be a single value.
16 | #' @return A modified version of `x` that replaces any values that
17 | #' are equal to `y` with `NA`.
18 | #' @seealso [coalesce()] to replace missing values with a specified
19 | #' value.
20 | #'
21 | #' [tidyr::replace_na()] to replace `NA` with a value.
22 | #' @export
23 | #' @examples
24 | #' na_if(1:5, 5:1)
25 | #'
26 | #' x <- c(1, -1, 0, 10)
27 | #' 100 / x
28 | #' 100 / na_if(x, 0)
29 | #'
30 | #' y <- c("abc", "def", "", "ghi")
31 | #' na_if(y, "")
32 | #'
33 | #' # `na_if()` allows you to replace `NaN` with `NA`,
34 | #' # even though `NaN == NaN` returns `NA`
35 | #' z <- c(1, NaN, NA, 2, NaN)
36 | #' na_if(z, NaN)
37 | #'
38 | #' # `na_if()` is particularly useful inside `mutate()`,
39 | #' # and is meant for use with vectors rather than entire data frames
40 | #' starwars %>%
41 | #' select(name, eye_color) %>%
42 | #' mutate(eye_color = na_if(eye_color, "unknown"))
43 | #'
44 | #' # `na_if()` can also be used with `mutate()` and `across()`
45 | #' # to alter multiple columns
46 | #' starwars %>%
47 | #' mutate(across(where(is.character), ~na_if(., "unknown")))
48 | na_if <- function(x, y) {
49 | # Type and size stable on `x`
50 | y <- vec_cast(x = y, to = x, x_arg = "y", to_arg = "x")
51 | y <- vec_recycle(y, size = vec_size(x), x_arg = "y")
52 |
53 | na <- vec_init(x)
54 | where <- vec_equal(x, y, na_equal = TRUE)
55 |
56 | x <- vec_assign(x, where, na)
57 |
58 | x
59 | }
60 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/R/reexport-magrittr.R:
--------------------------------------------------------------------------------
1 | #' @importFrom magrittr %>%
2 | #' @export
3 | magrittr::`%>%`
4 |
--------------------------------------------------------------------------------
/R/reexport-pillar.R:
--------------------------------------------------------------------------------
1 | #' Get a glimpse of your data
2 | #'
3 | #' @description
4 | #' `glimpse()` is like a transposed version of `print()`:
5 | #' columns run down the page, and data runs across.
6 | #' This makes it possible to see every column in a data frame.
7 | #' It's a little like [str()] applied to a data frame
8 | #' but it tries to show you as much data as possible.
9 | #' (And it always shows the underlying data, even when applied
10 | #' to a remote data source.)
11 | #'
12 | #' `glimpse()` is provided by the pillar package, and re-exported
13 | #' by dplyr. See [pillar::glimpse()] for more details.
14 | #'
15 | #' @return x original x is (invisibly) returned, allowing `glimpse()` to be
16 | #' used within a data pipeline.
17 | #' @examples
18 | #' glimpse(mtcars)
19 | #'
20 | #' # Note that original x is (invisibly) returned, allowing `glimpse()` to be
21 | #' # used within a pipeline.
22 | #' mtcars %>%
23 | #' glimpse() %>%
24 | #' select(1:3)
25 | #'
26 | #' glimpse(starwars)
27 | #' @importFrom pillar glimpse
28 | #' @export
29 | #' @name glimpse
30 | glimpse
31 |
32 | #' @importFrom pillar type_sum
33 | #' @export
34 | pillar::type_sum
35 |
--------------------------------------------------------------------------------
/R/reexport-tibble.R:
--------------------------------------------------------------------------------
1 | #' @importFrom tibble data_frame
2 | #' @export
3 | tibble::data_frame
4 |
5 | #' @importFrom tibble as_data_frame
6 | #' @export
7 | tibble::as_data_frame
8 |
9 | #' @importFrom tibble lst
10 | #' @export
11 | tibble::lst
12 |
13 | #' @importFrom tibble add_row
14 | #' @export
15 | tibble::add_row
16 |
17 | #' @importFrom tibble tribble
18 | #' @export
19 | tibble::tribble
20 |
21 | #' @importFrom tibble tibble
22 | #' @export
23 | tibble::tibble
24 |
25 | #' @importFrom tibble as_tibble
26 | #' @export
27 | tibble::as_tibble
28 |
29 | #' @importFrom tibble view
30 | tibble::view
31 |
--------------------------------------------------------------------------------
/R/src-dbi.R:
--------------------------------------------------------------------------------
1 | #' @export
2 | tbl.DBIConnection <- function(src, from, ...) {
3 | check_dbplyr()
4 | tbl(dbplyr::src_dbi(src, auto_disconnect = FALSE), from = from, ...)
5 | }
6 |
7 | #' @export
8 | copy_to.DBIConnection <- function(
9 | dest,
10 | df,
11 | name = deparse(substitute(df)),
12 | overwrite = FALSE,
13 | ...
14 | ) {
15 | check_dbplyr()
16 | copy_to(
17 | dbplyr::src_dbi(dest, auto_disconnect = FALSE),
18 | df = df,
19 | name = name,
20 | overwrite = overwrite,
21 | ...
22 | )
23 | }
24 |
--------------------------------------------------------------------------------
/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 | #' @param ... other arguments passed on to the individual methods.
36 | #' @export
37 | #' @keywords internal
38 | src_tbls <- function(x, ...) {
39 | UseMethod("src_tbls")
40 | }
41 |
42 | #' Figure out if two sources are the same (or two tbl have the same source)
43 | #'
44 | #' @param x,y src or tbls to test
45 | #' @return a logical flag
46 | #' @export
47 | #' @keywords internal
48 | same_src <- function(x, y) {
49 | UseMethod("same_src")
50 | }
51 |
52 | #' @export
53 | same_src.data.frame <- function(x, y) {
54 | is.data.frame(y)
55 | }
56 |
--------------------------------------------------------------------------------
/R/ts.R:
--------------------------------------------------------------------------------
1 | #' @export
2 | filter.ts <- function(.data, ...) {
3 | bullets <- c(
4 | "Incompatible data source.",
5 | x = '`.data` is a object, not a data source.',
6 | i = "Did you want to use `stats::filter()`?"
7 | )
8 | abort(bullets)
9 | }
10 |
--------------------------------------------------------------------------------
/R/utils-format.R:
--------------------------------------------------------------------------------
1 | #' Describing dimensions
2 | #'
3 | #' Prints the dimensions of an array-like object in a user-friendly manner,
4 | #' substituting `NA` with ?? (for SQL queries).
5 | #'
6 | #' @param x Object to show dimensions for.
7 | #' @export
8 | #' @keywords internal
9 | #' @examples
10 | #' dim_desc(mtcars)
11 | dim_desc <- function(x) {
12 | d <- dim(x)
13 | d2 <- big_mark(d)
14 | d2[is.na(d)] <- "??"
15 |
16 | paste0("[", paste0(d2, collapse = " x "), "]")
17 | }
18 |
19 | # function for the thousand separator,
20 | # returns "," unless it's used for the decimal point, in which case returns "."
21 | big_mark <- function(x, ...) {
22 | mark <- if (identical(getOption("OutDec"), ",")) "." else ","
23 | formatC(x, big.mark = mark, ...)
24 | }
25 |
26 | rule <- function(pad = "-", gap = 2L) {
27 | paste0(rep(pad, getOption("width") - gap), collapse = "")
28 | }
29 |
--------------------------------------------------------------------------------
/R/utils-tidy-eval.R:
--------------------------------------------------------------------------------
1 | #' Other tidy eval tools
2 | #'
3 | #' @description
4 | #' These tidy eval functions are no longer for normal usage, but are still
5 | #' exported from dplyr for backward compatibility.
6 | #' See [`?rlang::args_data_masking`][rlang::args_data_masking] and
7 | #' `vignette("programming")` for the latest recommendations.
8 | #'
9 | #' * [expr()][rlang::expr]
10 | #' * [enquo()][rlang::enquo]
11 | #' * [enquos()][rlang::enquos]
12 | #' * [sym()][rlang::sym]
13 | #' * [syms()][rlang::syms]
14 | #' * [as_label()][rlang::as_label]
15 | #' * [quo()][rlang::quo]
16 | #' * [quos()][rlang::quos]
17 | #' * [quo_name()][rlang::quo_name]
18 | #' * [ensym()][rlang::ensym]
19 | #' * [ensyms()][rlang::ensyms]
20 | #' * [enexpr()][rlang::enexpr]
21 | #' * [enexprs()][rlang::enexprs]
22 | #'
23 | #' @keywords internal
24 | #' @name tidyeval-compat
25 | #' @aliases .data expr enquo enquos sym syms as_label
26 | #' @export .data expr enquo enquos sym syms as_label
27 | #' @aliases quo quos quo_name ensym ensyms enexpr enexprs
28 | #' @export quo quos quo_name ensym ensyms enexpr enexprs
29 | NULL
30 |
31 | # Retaining a redirect for the old `dplyr_data_masking` help page, because many
32 | # package authors end up linking to this through inherited documentation, and
33 | # removing the topic from here results in a check warning in their package. It
34 | # should be possible to remove this once enough packages have re-documented with
35 | # dplyr 1.1.1 installed and sent a new release to CRAN.
36 | #' Data-masking
37 | #'
38 | #' This page is now located at
39 | #' [`?rlang::args_data_masking`][rlang::args_data_masking].
40 | #'
41 | #' @keywords internal
42 | #' @name dplyr_data_masking
43 | NULL
44 |
--------------------------------------------------------------------------------
/R/vctrs.R:
--------------------------------------------------------------------------------
1 | common_handler <- function(name) {
2 | function(cnd) {
3 | bullets <- c(
4 | glue("`{name}` must return compatible vectors across groups."),
5 | i = cnd_bullet_combine_details(cnd$x, cnd$x_arg),
6 | i = cnd_bullet_combine_details(cnd$y, cnd$y_arg)
7 | )
8 | abort(bullets, class = "dplyr:::error_incompatible_combine")
9 | }
10 | }
11 |
12 | dplyr_vec_cast_common <- function(chunks, name) {
13 | withCallingHandlers(
14 | vec_cast_common(!!!chunks),
15 | error = common_handler(name)
16 | )
17 | }
18 | dplyr_vec_ptype_common <- function(chunks, name) {
19 | withCallingHandlers(
20 | vec_ptype_common(!!!chunks),
21 | error = common_handler(name)
22 | )
23 | }
24 |
--------------------------------------------------------------------------------
/R/vec-case-match.R:
--------------------------------------------------------------------------------
1 | vec_case_match <- function(
2 | needles,
3 | haystacks,
4 | values,
5 | ...,
6 | needles_arg = "needles",
7 | haystacks_arg = "haystacks",
8 | values_arg = "values",
9 | default = NULL,
10 | default_arg = "default",
11 | ptype = NULL,
12 | call = current_env()
13 | ) {
14 | check_dots_empty0(...)
15 |
16 | obj_check_vector(needles, arg = needles_arg, call = call)
17 | obj_check_list(haystacks, arg = haystacks_arg, call = call)
18 | list_check_all_vectors(haystacks, arg = haystacks_arg, call = call)
19 |
20 | haystacks <- vec_cast_common(
21 | !!!haystacks,
22 | .to = needles,
23 | .arg = haystacks_arg,
24 | .call = call
25 | )
26 |
27 | # Could be more efficient in C. Build a dictionary on `needles`
28 | # once and then reuse it with each haystack
29 | conditions <- map(haystacks, vec_in, needles = needles)
30 |
31 | size <- vec_size(needles)
32 |
33 | vec_case_when(
34 | conditions = conditions,
35 | values = values,
36 | conditions_arg = "",
37 | values_arg = values_arg,
38 | default = default,
39 | default_arg = default_arg,
40 | ptype = ptype,
41 | size = size,
42 | call = call
43 | )
44 | }
45 |
--------------------------------------------------------------------------------
/R/zzz.R:
--------------------------------------------------------------------------------
1 | .onLoad <- function(libname, pkgname) {
2 | ns_dplyr <- ns_env(pkgname)
3 |
4 | op <- options()
5 | op.dplyr <- list(
6 | dplyr.show_progress = TRUE
7 | )
8 | toset <- !(names(op.dplyr) %in% names(op))
9 | if (any(toset)) options(op.dplyr[toset])
10 |
11 | .Call(dplyr_init_library, ns_dplyr, ns_env("vctrs"), ns_env("rlang"))
12 |
13 | # TODO: For `arrange()`, `group_by()`, `with_order()`, and `nth()` until vctrs
14 | # changes `vec_order()` to the new ordering algorithm, at which point we
15 | # should switch from `vec_order_radix()` to `vec_order()` so vctrs can remove
16 | # it.
17 | env_bind(
18 | .env = ns_dplyr,
19 | vec_order_radix = import_vctrs("vec_order_radix")
20 | )
21 |
22 | run_on_load()
23 |
24 | invisible()
25 | }
26 |
27 | .onAttach <- function(libname, pkgname) {
28 | setHook(packageEvent("plyr", "attach"), function(...) {
29 | packageStartupMessage(rule())
30 | packageStartupMessage(
31 | "You have loaded plyr after dplyr - this is likely ",
32 | "to cause problems.\nIf you need functions from both plyr and dplyr, ",
33 | "please load plyr first, then dplyr:\nlibrary(plyr); library(dplyr)"
34 | )
35 | packageStartupMessage(rule())
36 | })
37 | }
38 |
39 | .onDetach <- function(libpath) {
40 | setHook(packageEvent("plyr", "attach"), NULL, "replace")
41 | }
42 |
43 | import_vctrs <- function(name, optional = FALSE) {
44 | import_from(name, "vctrs", optional = optional)
45 | }
46 | import_from <- function(name, package, optional = FALSE) {
47 | ns <- getNamespace(package)
48 |
49 | if (!exists(name, mode = "function", envir = ns, inherits = FALSE)) {
50 | if (optional) {
51 | return(NULL)
52 | }
53 | abort(sprintf("No such '%s' function: `%s()`.", package, name))
54 | }
55 |
56 | get(name, mode = "function", envir = ns, inherits = FALSE)
57 | }
58 |
--------------------------------------------------------------------------------
/air.toml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/air.toml
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | comment: false
2 |
3 | coverage:
4 | status:
5 | project:
6 | default:
7 | target: auto
8 | threshold: 1%
9 | informational: true
10 | patch:
11 | default:
12 | target: auto
13 | threshold: 1%
14 | informational: true
15 |
--------------------------------------------------------------------------------
/cran-comments.md:
--------------------------------------------------------------------------------
1 | We don't expect any reverse dependency failures.
2 |
3 | This patch release contains a few minor bug fixes.
4 |
--------------------------------------------------------------------------------
/data-raw/band_members.R:
--------------------------------------------------------------------------------
1 | library(tidyverse)
2 |
3 | # fmt: skip
4 | band_members <- tribble(
5 | ~ name, ~ band,
6 | "Mick", "Stones",
7 | "John", "Beatles",
8 | "Paul", "Beatles"
9 | )
10 |
11 | devtools::use_data(band_members)
12 |
13 | # fmt: skip
14 | band_instruments <- tribble(
15 | ~ name, ~ plays,
16 | "John", "guitar",
17 | "Paul", "bass",
18 | "Keith", "guitar"
19 | )
20 |
21 | devtools::use_data(band_instruments)
22 |
23 | # fmt: skip
24 | band_instruments2 <- tribble(
25 | ~ artist, ~ plays,
26 | "John", "guitar",
27 | "Paul", "bass",
28 | "Keith", "guitar"
29 | )
30 |
31 | devtools::use_data(band_instruments2)
32 |
--------------------------------------------------------------------------------
/data/band_instruments.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/data/band_instruments.rda
--------------------------------------------------------------------------------
/data/band_instruments2.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/data/band_instruments2.rda
--------------------------------------------------------------------------------
/data/band_members.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/data/band_members.rda
--------------------------------------------------------------------------------
/data/starwars.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/data/starwars.rda
--------------------------------------------------------------------------------
/data/storms.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/data/storms.rda
--------------------------------------------------------------------------------
/dplyr.Rproj:
--------------------------------------------------------------------------------
1 | Version: 1.0
2 |
3 | RestoreWorkspace: Default
4 | SaveWorkspace: Default
5 | AlwaysSaveHistory: Default
6 |
7 | EnableCodeIndexing: Yes
8 | UseSpacesForTab: Yes
9 | NumSpacesForTab: 2
10 | Encoding: UTF-8
11 |
12 | RnwWeave: Sweave
13 | LaTeX: pdfLaTeX
14 |
15 | AutoAppendNewline: Yes
16 | StripTrailingWhitespace: Yes
17 |
18 | BuildType: Package
19 | PackageUseDevtools: Yes
20 | PackageInstallArgs: --no-multiarch --with-keep.source --install-tests
21 | PackageRoxygenize: rd,collate,namespace
22 |
--------------------------------------------------------------------------------
/inst/db/.gitignore:
--------------------------------------------------------------------------------
1 | *.sqlite
2 |
--------------------------------------------------------------------------------
/man/add_rownames.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/deprec-tibble.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 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
16 | Please use \code{\link[tibble:rownames]{tibble::rownames_to_column()}} instead.
17 | }
18 | \keyword{internal}
19 |
--------------------------------------------------------------------------------
/man/all_equal.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/all-equal.R
3 | \name{all_equal}
4 | \alias{all_equal}
5 | \title{Flexible equality comparison for data frames}
6 | \usage{
7 | all_equal(
8 | target,
9 | current,
10 | ignore_col_order = TRUE,
11 | ignore_row_order = TRUE,
12 | convert = FALSE,
13 | ...
14 | )
15 | }
16 | \arguments{
17 | \item{target, current}{Two data frames to compare.}
18 |
19 | \item{ignore_col_order}{Should order of columns be ignored?}
20 |
21 | \item{ignore_row_order}{Should order of rows be ignored?}
22 |
23 | \item{convert}{Should similar classes be converted? Currently this will
24 | convert factor to character and integer to double.}
25 |
26 | \item{...}{Ignored. Needed for compatibility with \code{all.equal()}.}
27 | }
28 | \value{
29 | \code{TRUE} if equal, otherwise a character vector describing
30 | the reasons why they're not equal. Use \code{\link[=isTRUE]{isTRUE()}} if using the
31 | result in an \code{if} expression.
32 | }
33 | \description{
34 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
35 |
36 | \code{all_equal()} allows you to compare data frames, optionally ignoring
37 | row and column names. It is deprecated as of dplyr 1.1.0, because it
38 | makes it too easy to ignore important differences.
39 | }
40 | \examples{
41 | scramble <- function(x) x[sample(nrow(x)), sample(ncol(x))]
42 |
43 | # `all_equal()` ignored row and column ordering by default,
44 | # but we now feel that that makes it too easy to make mistakes
45 | mtcars2 <- scramble(mtcars)
46 | all_equal(mtcars, mtcars2)
47 |
48 | # Instead, be explicit about the row and column ordering
49 | all.equal(
50 | mtcars,
51 | mtcars2[rownames(mtcars), names(mtcars)]
52 | )
53 | }
54 | \keyword{internal}
55 |
--------------------------------------------------------------------------------
/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}{<\code{\link[rlang:args_data_masking]{data-masking}}> An expression that
14 | returns a logical vector, using \code{.} to refer to the "current" variable.}
15 | }
16 | \description{
17 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}
18 |
19 | \code{all_vars()} and \code{any_vars()} were only needed for the scoped verbs, which
20 | have been superseded by the use of \code{\link[=across]{across()}} in an existing verb. See
21 | \code{vignette("colwise")} for details.
22 |
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[=vars]{vars()}} for other quoting functions that you
31 | can use with scoped verbs.
32 | }
33 |
--------------------------------------------------------------------------------
/man/args_by.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/by.R
3 | \name{args_by}
4 | \alias{args_by}
5 | \title{Helper for consistent documentation of \code{.by}}
6 | \arguments{
7 | \item{.by}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
8 |
9 | <\code{\link[=dplyr_tidy_select]{tidy-select}}> Optionally, a selection of columns to
10 | group by for just this operation, functioning as an alternative to \code{\link[=group_by]{group_by()}}. For
11 | details and examples, see \link[=dplyr_by]{?dplyr_by}.}
12 | }
13 | \description{
14 | Use \verb{@inheritParams args_by} to consistently document \code{.by}.
15 | }
16 | \keyword{internal}
17 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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{
10 | Each is a tibble with two variables and three observations
11 | }
12 | \usage{
13 | band_members
14 |
15 | band_instruments
16 |
17 | band_instruments2
18 | }
19 | \description{
20 | These data sets describe band members of the Beatles and Rolling Stones. They
21 | are toy data sets that can be displayed in their entirety on a slide (e.g. to
22 | demonstrate a join).
23 | }
24 | \details{
25 | \code{band_instruments} and \code{band_instruments2} contain the same data but use
26 | different column names for the first column of the data set.
27 | \code{band_instruments} uses \code{name}, which matches the name of the key column of
28 | \code{band_members}; \code{band_instruments2} uses \code{artist}, which does not.
29 | }
30 | \examples{
31 | band_members
32 | band_instruments
33 | band_instruments2
34 | }
35 | \keyword{datasets}
36 |
--------------------------------------------------------------------------------
/man/between.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/funs.R
3 | \name{between}
4 | \alias{between}
5 | \title{Detect where values fall in a specified range}
6 | \usage{
7 | between(x, left, right, ..., ptype = NULL)
8 | }
9 | \arguments{
10 | \item{x}{A vector}
11 |
12 | \item{left, right}{Boundary values. Both \code{left} and \code{right} are recycled to
13 | the size of \code{x}.}
14 |
15 | \item{...}{These dots are for future extensions and must be empty.}
16 |
17 | \item{ptype}{An optional prototype giving the desired output type. The
18 | default is to compute the common type of \code{x}, \code{left}, and \code{right} using
19 | \code{\link[vctrs:vec_cast]{vctrs::vec_cast_common()}}.}
20 | }
21 | \value{
22 | A logical vector the same size as \code{x} with a type determined by \code{ptype}.
23 | }
24 | \description{
25 | This is a shortcut for \code{x >= left & x <= right}, implemented for local
26 | vectors and translated to the appropriate SQL for remote tables.
27 | }
28 | \details{
29 | \code{x}, \code{left}, and \code{right} are all cast to their common type before the
30 | comparison is made. Use the \code{ptype} argument to specify the type manually.
31 | }
32 | \examples{
33 | between(1:12, 7, 9)
34 |
35 | x <- rnorm(1e2)
36 | x[between(x, -1, 1)]
37 |
38 | # On a tibble using `filter()`
39 | filter(starwars, between(height, 100, 150))
40 |
41 | # Using the `ptype` argument with ordered factors, where otherwise everything
42 | # is cast to the common type of character before the comparison
43 | x <- ordered(
44 | c("low", "medium", "high", "medium"),
45 | levels = c("low", "medium", "high")
46 | )
47 | between(x, "medium", "high")
48 | between(x, "medium", "high", ptype = x)
49 | }
50 | \seealso{
51 | \code{\link[=join_by]{join_by()}} if you are looking for documentation for the \code{between()} overlap
52 | join helper.
53 | }
54 |
--------------------------------------------------------------------------------
/man/bind_cols.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/bind-cols.R
3 | \name{bind_cols}
4 | \alias{bind_cols}
5 | \title{Bind multiple data frames by column}
6 | \usage{
7 | bind_cols(
8 | ...,
9 | .name_repair = c("unique", "universal", "check_unique", "minimal")
10 | )
11 | }
12 | \arguments{
13 | \item{...}{Data frames to combine. Each argument can either be a data frame,
14 | a list that could be a data frame, or a list of data frames.
15 | Inputs are \link[vctrs:theory-faq-recycling]{recycled} to the same length,
16 | then matched by position.}
17 |
18 | \item{.name_repair}{One of \code{"unique"}, \code{"universal"}, or
19 | \code{"check_unique"}. See \code{\link[vctrs:vec_as_names]{vctrs::vec_as_names()}} for the meaning of these
20 | options.}
21 | }
22 | \value{
23 | A data frame the same type as the first element of \code{...}.
24 | }
25 | \description{
26 | Bind any number of data frames by column, making a wider result.
27 | This is similar to \code{do.call(cbind, dfs)}.
28 |
29 | Where possible prefer using a \link[=left_join]{join} to combine multiple
30 | data frames. \code{bind_cols()} binds the rows in order in which they appear
31 | so it is easy to create meaningless results without realising it.
32 | }
33 | \examples{
34 | df1 <- tibble(x = 1:3)
35 | df2 <- tibble(y = 3:1)
36 | bind_cols(df1, df2)
37 |
38 | # Row sizes must be compatible when column-binding
39 | try(bind_cols(tibble(x = 1:3), tibble(y = 1:2)))
40 | }
41 |
--------------------------------------------------------------------------------
/man/bind_rows.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/bind-rows.R
3 | \name{bind_rows}
4 | \alias{bind_rows}
5 | \alias{bind}
6 | \title{Bind multiple data frames by row}
7 | \usage{
8 | bind_rows(..., .id = NULL)
9 | }
10 | \arguments{
11 | \item{...}{Data frames to combine. Each argument can either be a data frame,
12 | a list that could be a data frame, or a list of data frames. Columns are
13 | matched by name, and any missing columns will be filled with \code{NA}.}
14 |
15 | \item{.id}{The name of an optional identifier column. Provide a string to
16 | create an output column that identifies each input. The column will use
17 | names if available, otherwise it will use positions.}
18 | }
19 | \value{
20 | A data frame the same type as the first element of \code{...}.
21 | }
22 | \description{
23 | Bind any number of data frames by row, making a longer result. This is
24 | similar to \code{do.call(rbind, dfs)}, but the output will contain all columns
25 | that appear in any of the inputs.
26 | }
27 | \examples{
28 | df1 <- tibble(x = 1:2, y = letters[1:2])
29 | df2 <- tibble(x = 4:5, z = 1:2)
30 |
31 | # You can supply individual data frames as arguments:
32 | bind_rows(df1, df2)
33 |
34 | # Or a list of data frames:
35 | bind_rows(list(df1, df2))
36 |
37 | # When you supply a column name with the `.id` argument, a new
38 | # column is created to link each row to its original data frame
39 | bind_rows(list(df1, df2), .id = "id")
40 | bind_rows(list(a = df1, b = df2), .id = "id")
41 | }
42 |
--------------------------------------------------------------------------------
/man/c_across.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/across.R
3 | \name{c_across}
4 | \alias{c_across}
5 | \title{Combine values from multiple columns}
6 | \usage{
7 | c_across(cols)
8 | }
9 | \arguments{
10 | \item{cols}{<\code{\link[=dplyr_tidy_select]{tidy-select}}> Columns to transform.
11 | You can't select grouping columns because they are already automatically
12 | handled by the verb (i.e. \code{\link[=summarise]{summarise()}} or \code{\link[=mutate]{mutate()}}).}
13 | }
14 | \description{
15 | \code{c_across()} is designed to work with \code{\link[=rowwise]{rowwise()}} to make it easy to
16 | perform row-wise aggregations. It has two differences from \code{c()}:
17 | \itemize{
18 | \item It uses tidy select semantics so you can easily select multiple variables.
19 | See \code{vignette("rowwise")} for more details.
20 | \item It uses \code{\link[vctrs:vec_c]{vctrs::vec_c()}} in order to give safer outputs.
21 | }
22 | }
23 | \examples{
24 | df <- tibble(id = 1:4, w = runif(4), x = runif(4), y = runif(4), z = runif(4))
25 | df \%>\%
26 | rowwise() \%>\%
27 | mutate(
28 | sum = sum(c_across(w:z)),
29 | sd = sd(c_across(w:z))
30 | )
31 | }
32 | \seealso{
33 | \code{\link[=across]{across()}} for a function that returns a tibble.
34 | }
35 |
--------------------------------------------------------------------------------
/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 | \dontshow{if (requireNamespace("dbplyr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
22 | wrap_dbplyr_obj("build_sql")
23 | wrap_dbplyr_obj("base_agg")
24 | \dontshow{\}) # examplesIf}
25 | }
26 | \keyword{internal}
27 |
--------------------------------------------------------------------------------
/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 the first non-missing element}
6 | \usage{
7 | coalesce(..., .ptype = NULL, .size = NULL)
8 | }
9 | \arguments{
10 | \item{...}{<\code{\link[rlang:dyn-dots]{dynamic-dots}}>
11 |
12 | One or more vectors. These will be
13 | \link[vctrs:theory-faq-recycling]{recycled} against each other, and will be
14 | cast to their common type.}
15 |
16 | \item{.ptype}{An optional prototype declaring the desired output type. If
17 | supplied, this overrides the common type of the vectors in \code{...}.}
18 |
19 | \item{.size}{An optional size declaring the desired output size. If supplied,
20 | this overrides the common size of the vectors in \code{...}.}
21 | }
22 | \value{
23 | A vector with the same type and size as the common type and common
24 | size of the vectors in \code{...}.
25 | }
26 | \description{
27 | Given a set of vectors, \code{coalesce()} finds the first non-missing value at
28 | each position. It's inspired by the SQL \code{COALESCE} function which does the
29 | same thing for SQL \code{NULL}s.
30 | }
31 | \examples{
32 | # Use a single value to replace all missing values
33 | x <- sample(c(1:5, NA, NA, NA))
34 | coalesce(x, 0L)
35 |
36 | # The equivalent to a missing value in a list is `NULL`
37 | coalesce(list(1, 2, NULL), list(NA))
38 |
39 | # Or generate a complete vector from partially missing pieces
40 | y <- c(1, 2, NA, NA, 5)
41 | z <- c(NA, NA, 3, 4, 5)
42 | coalesce(y, z)
43 |
44 | # Supply lists by splicing them into dots:
45 | vecs <- list(
46 | c(1, 2, NA, NA, 5),
47 | c(NA, NA, 3, 4, 5)
48 | )
49 | coalesce(!!!vecs)
50 | }
51 | \seealso{
52 | \code{\link[=na_if]{na_if()}} to replace specified values with an \code{NA}.
53 | \code{\link[tidyr:replace_na]{tidyr::replace_na()}} to replace \code{NA} with a value.
54 | }
55 |
--------------------------------------------------------------------------------
/man/combine.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/deprec-combine.R
3 | \name{combine}
4 | \alias{combine}
5 | \title{Combine vectors}
6 | \usage{
7 | combine(...)
8 | }
9 | \arguments{
10 | \item{...}{Vectors to combine.}
11 | }
12 | \description{
13 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
14 |
15 | \code{combine()} is deprecated in favour of \code{\link[vctrs:vec_c]{vctrs::vec_c()}}. \code{combine()}
16 | attempted to automatically guess whether you wanted \code{\link[=c]{c()}} or \code{\link[=unlist]{unlist()}},
17 | but could fail in surprising ways. We now believe it's better to be explicit.
18 | }
19 | \examples{
20 | f1 <- factor("a")
21 | f2 <- factor("b")
22 |
23 | combine(f1, f2)
24 | # ->
25 | vctrs::vec_c(f1, f1)
26 |
27 | combine(list(f1, f2))
28 | # ->
29 | vctrs::vec_c(!!!list(f1, f2))
30 | }
31 | \keyword{internal}
32 |
--------------------------------------------------------------------------------
/man/common_by.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/join-common-by.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 |
--------------------------------------------------------------------------------
/man/consecutive_id.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/consecutive-id.R
3 | \name{consecutive_id}
4 | \alias{consecutive_id}
5 | \title{Generate a unique identifier for consecutive combinations}
6 | \usage{
7 | consecutive_id(...)
8 | }
9 | \arguments{
10 | \item{...}{Unnamed vectors. If multiple vectors are supplied, then they should
11 | have the same length.}
12 | }
13 | \value{
14 | A numeric vector the same length as the longest
15 | element of \code{...}.
16 | }
17 | \description{
18 | \code{consecutive_id()} generates a unique identifier that increments every time
19 | a variable (or combination of variables) changes. Inspired by
20 | \code{data.table::rleid()}.
21 | }
22 | \examples{
23 | consecutive_id(c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, NA, NA))
24 | consecutive_id(c(1, 1, 1, 2, 1, 1, 2, 2))
25 |
26 | df <- data.frame(x = c(0, 0, 1, 0), y = c(2, 2, 2, 2))
27 | df \%>\% group_by(x, y) \%>\% summarise(n = n())
28 | df \%>\% group_by(id = consecutive_id(x, y), x, y) \%>\% summarise(n = n())
29 | }
30 |
--------------------------------------------------------------------------------
/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 | \section{Methods}{
31 |
32 | This function is a \strong{generic}, which means that packages can provide
33 | implementations (methods) for other classes. See the documentation of
34 | individual methods for extra arguments and differences in behaviour.
35 |
36 | The following methods are currently available in loaded packages:
37 | \Sexpr[stage=render,results=rd]{dplyr:::methods_rd("copy_to")}.
38 | }
39 |
40 | \examples{
41 | \dontrun{
42 | iris2 <- dbplyr::src_memdb() \%>\% copy_to(iris, overwrite = TRUE)
43 | iris2
44 | }
45 | }
46 | \seealso{
47 | \code{\link[=collect]{collect()}} for the opposite action; downloading remote data into
48 | a local dbl.
49 | }
50 |
--------------------------------------------------------------------------------
/man/cumall.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/funs.R
3 | \name{cumall}
4 | \alias{cumall}
5 | \alias{cumany}
6 | \alias{cummean}
7 | \title{Cumulative 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 | \value{
20 | A vector the same length as \code{x}.
21 | }
22 | \description{
23 | dplyr provides \code{cumall()}, \code{cumany()}, and \code{cummean()} to complete R's set
24 | of cumulative functions.
25 | }
26 | \section{Cumulative logical functions}{
27 |
28 |
29 | These are particularly useful in conjunction with \code{filter()}:
30 | \itemize{
31 | \item \code{cumall(x)}: all cases until the first \code{FALSE}.
32 | \item \code{cumall(!x)}: all cases until the first \code{TRUE}.
33 | \item \code{cumany(x)}: all cases after the first \code{TRUE}.
34 | \item \code{cumany(!x)}: all cases after the first \code{FALSE}.
35 | }
36 | }
37 |
38 | \examples{
39 | # `cummean()` returns a numeric/integer vector of the same length
40 | # as the input vector.
41 | x <- c(1, 3, 5, 2, 2)
42 | cummean(x)
43 | cumsum(x) / seq_along(x)
44 |
45 | # `cumall()` and `cumany()` return logicals
46 | cumall(x < 5)
47 | cumany(x == 3)
48 |
49 | # `cumall()` vs. `cumany()`
50 | df <- data.frame(
51 | date = as.Date("2020-01-01") + 0:6,
52 | balance = c(100, 50, 25, -25, -50, 30, 120)
53 | )
54 | # all rows after first overdraft
55 | df \%>\% filter(cumany(balance < 0))
56 | # all rows until first overdraft
57 | df \%>\% filter(cumall(!(balance < 0)))
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/man/defunct.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/defunct.R
3 | \name{defunct}
4 | \alias{defunct}
5 | \alias{id}
6 | \alias{failwith}
7 | \alias{select_vars}
8 | \alias{rename_vars}
9 | \alias{select_var}
10 | \alias{current_vars}
11 | \alias{bench_tbls}
12 | \alias{compare_tbls}
13 | \alias{compare_tbls2}
14 | \alias{eval_tbls}
15 | \alias{eval_tbls2}
16 | \alias{location}
17 | \alias{changes}
18 | \title{Defunct functions}
19 | \usage{
20 | # Deprecated in 0.5.0 -------------------------------------
21 |
22 | id(.variables, drop = FALSE)
23 |
24 | # Deprecated in 0.7.0 -------------------------------------
25 |
26 | failwith(default = NULL, f, quiet = FALSE)
27 |
28 | # Deprecated in 0.8.* -------------------------------------
29 |
30 | select_vars(vars = chr(), ..., include = chr(), exclude = chr())
31 |
32 | rename_vars(vars = chr(), ..., strict = TRUE)
33 |
34 | select_var(vars, var = -1)
35 |
36 | current_vars(...)
37 |
38 | # Deprecated in 1.0.0 -------------------------------------
39 |
40 | bench_tbls(tbls, op, ..., times = 10)
41 |
42 | compare_tbls(tbls, op, ref = NULL, compare = equal_data_frame, ...)
43 |
44 | compare_tbls2(tbls_x, tbls_y, op, ref = NULL, compare = equal_data_frame, ...)
45 |
46 | eval_tbls(tbls, op)
47 |
48 | eval_tbls2(tbls_x, tbls_y, op)
49 |
50 | location(df)
51 |
52 | changes(x, y)
53 | }
54 | \description{
55 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#defunct}{\figure{lifecycle-defunct.svg}{options: alt='[Defunct]'}}}{\strong{[Defunct]}}
56 |
57 | These functions were deprecated for at least two years before being
58 | made defunct. If there's a known replacement, calling the function
59 | will tell you about it.
60 | }
61 | \keyword{internal}
62 |
--------------------------------------------------------------------------------
/man/deprec-context.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/deprec-context.R
3 | \name{deprec-context}
4 | \alias{deprec-context}
5 | \alias{cur_data}
6 | \alias{cur_data_all}
7 | \title{Information about the "current" group or variable}
8 | \usage{
9 | cur_data()
10 |
11 | cur_data_all()
12 | }
13 | \description{
14 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
15 |
16 | These functions were deprecated in dplyr 1.1.0.
17 | \itemize{
18 | \item \code{cur_data()} is deprecated in favor of \code{\link[=pick]{pick()}}.
19 | \item \code{cur_data_all()} is deprecated but does not have a direct replacement as
20 | selecting the grouping variables is not well-defined and is unlikely to
21 | ever be useful.
22 | }
23 | }
24 | \keyword{internal}
25 |
--------------------------------------------------------------------------------
/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/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/dplyr-package.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/dplyr.R
3 | \docType{package}
4 | \name{dplyr-package}
5 | \alias{dplyr}
6 | \alias{dplyr-package}
7 | \title{dplyr: A Grammar of Data Manipulation}
8 | \description{
9 | To learn more about dplyr, start with the vignettes:
10 | \code{browseVignettes(package = "dplyr")}
11 | }
12 | \seealso{
13 | Useful links:
14 | \itemize{
15 | \item \url{https://dplyr.tidyverse.org}
16 | \item \url{https://github.com/tidyverse/dplyr}
17 | \item Report bugs at \url{https://github.com/tidyverse/dplyr/issues}
18 | }
19 |
20 | }
21 | \author{
22 | \strong{Maintainer}: Hadley Wickham \email{hadley@posit.co} (\href{https://orcid.org/0000-0003-4757-117X}{ORCID})
23 |
24 | Authors:
25 | \itemize{
26 | \item Romain François (\href{https://orcid.org/0000-0002-2444-4226}{ORCID})
27 | \item Lionel Henry
28 | \item Kirill Müller (\href{https://orcid.org/0000-0002-1416-3412}{ORCID})
29 | \item Davis Vaughan \email{davis@posit.co} (\href{https://orcid.org/0000-0003-4777-038X}{ORCID})
30 | }
31 |
32 | Other contributors:
33 | \itemize{
34 | \item Posit Software, PBC [copyright holder, funder]
35 | }
36 |
37 | }
38 | \keyword{internal}
39 |
--------------------------------------------------------------------------------
/man/dplyr_data_masking.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/utils-tidy-eval.R
3 | \name{dplyr_data_masking}
4 | \alias{dplyr_data_masking}
5 | \title{Data-masking}
6 | \description{
7 | This page is now located at
8 | \code{\link[rlang:args_data_masking]{?rlang::args_data_masking}}.
9 | }
10 | \keyword{internal}
11 |
--------------------------------------------------------------------------------
/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 | \dontshow{if (requireNamespace("dbplyr", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
35 | \donttest{
36 | lahman_s <- dbplyr::lahman_sqlite()
37 | batting <- tbl(lahman_s, "Batting")
38 | batting \%>\% show_query()
39 | batting \%>\% explain()
40 |
41 | # The batting database has indices on all ID variables:
42 | # SQLite automatically picks the most restrictive index
43 | batting \%>\% filter(lgID == "NL" & yearID == 2000L) \%>\% explain()
44 |
45 | # OR's will use multiple indexes
46 | batting \%>\% filter(lgID == "NL" | yearID == 2000) \%>\% explain()
47 |
48 | # Joins will use indexes in both tables
49 | teams <- tbl(lahman_s, "Teams")
50 | batting \%>\% left_join(teams, c("yearID", "teamID")) \%>\% explain()
51 | }
52 | \dontshow{\}) # examplesIf}
53 | }
54 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-archived.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-defunct.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-deprecated.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-experimental.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-maturing.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-questioning.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-retired.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-soft-deprecated.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-stable.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/lifecycle-superseded.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/man/figures/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/man/figures/logo.png
--------------------------------------------------------------------------------
/man/funs.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/deprec-funs.R
3 | \name{funs}
4 | \alias{funs}
5 | \title{Create a list of function calls}
6 | \usage{
7 | funs(..., .args = list())
8 | }
9 | \arguments{
10 | \item{...}{<\code{\link[rlang:args_data_masking]{data-masking}}> A list of functions
11 | specified by:
12 | \itemize{
13 | \item Their name, \code{"mean"}
14 | \item The function itself, \code{mean}
15 | \item A call to the function with \code{.} as a dummy argument,
16 | \code{mean(., na.rm = TRUE)}
17 | }
18 |
19 | The following notations are \strong{not} supported, see examples:
20 | \itemize{
21 | \item An anonymous function, \code{function(x) mean(x, na.rm = TRUE)}
22 | \item An anonymous function in \pkg{purrr} notation, \code{~mean(., na.rm = TRUE)}
23 | }}
24 |
25 | \item{.args, args}{A named list of additional arguments to be added to all
26 | function calls. As \code{funs()} is being deprecated, use other methods to
27 | supply arguments: \code{...} argument in \link[=summarise_at]{scoped verbs} or make
28 | own functions with \code{\link[purrr:partial]{purrr::partial()}}.}
29 | }
30 | \description{
31 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
32 |
33 | \code{funs()} is deprecated; please use \code{list()} instead. We deprecated this
34 | function because it provided a unique way of specifying anonymous functions,
35 | rather than adopting the conventions used by purrr and other packages
36 | in the tidyverse.
37 | }
38 | \examples{
39 | funs("mean", mean(., na.rm = TRUE))
40 | # ->
41 | list(mean = mean, mean = ~ mean(.x, na.rm = TRUE))
42 |
43 | funs(m1 = mean, m2 = "mean", m3 = mean(., na.rm = TRUE))
44 | # ->
45 | list(m1 = mean, m2 = "mean", m3 = ~ mean(.x, na.rm = TRUE))
46 | }
47 | \keyword{internal}
48 |
--------------------------------------------------------------------------------
/man/glimpse.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/reexport-pillar.R
3 | \name{glimpse}
4 | \alias{glimpse}
5 | \title{Get a glimpse of your data}
6 | \value{
7 | x original x is (invisibly) returned, allowing \code{glimpse()} to be
8 | used within a data pipeline.
9 | }
10 | \description{
11 | \code{glimpse()} is like a transposed version of \code{print()}:
12 | columns run down the page, and data runs across.
13 | This makes it possible to see every column in a data frame.
14 | It's a little like \code{\link[=str]{str()}} applied to a data frame
15 | but it tries to show you as much data as possible.
16 | (And it always shows the underlying data, even when applied
17 | to a remote data source.)
18 |
19 | \code{glimpse()} is provided by the pillar package, and re-exported
20 | by dplyr. See \code{\link[pillar:glimpse]{pillar::glimpse()}} for more details.
21 | }
22 | \examples{
23 | glimpse(mtcars)
24 |
25 | # Note that original x is (invisibly) returned, allowing `glimpse()` to be
26 | # used within a pipeline.
27 | mtcars \%>\%
28 | glimpse() \%>\%
29 | select(1:3)
30 |
31 | glimpse(starwars)
32 | }
33 |
--------------------------------------------------------------------------------
/man/group_by_drop_default.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/group-by.R
3 | \name{group_by_drop_default}
4 | \alias{group_by_drop_default}
5 | \title{Default value for .drop argument of group_by}
6 | \usage{
7 | group_by_drop_default(.tbl)
8 | }
9 | \arguments{
10 | \item{.tbl}{A data frame}
11 | }
12 | \value{
13 | \code{TRUE} unless \code{.tbl} is a grouped data frame that was previously
14 | obtained by \code{group_by(.drop = FALSE)}
15 | }
16 | \description{
17 | Default value for .drop argument of group_by
18 | }
19 | \examples{
20 | group_by_drop_default(iris)
21 |
22 | iris \%>\%
23 | group_by(Species) \%>\%
24 | group_by_drop_default()
25 |
26 | iris \%>\%
27 | group_by(Species, .drop = FALSE) \%>\%
28 | group_by_drop_default()
29 |
30 | }
31 | \keyword{internal}
32 |
--------------------------------------------------------------------------------
/man/group_by_prepare.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/distinct.R, R/group-by.R
3 | \name{distinct_prepare}
4 | \alias{distinct_prepare}
5 | \alias{group_by_prepare}
6 | \title{Prepare for grouping and other operations}
7 | \usage{
8 | distinct_prepare(
9 | .data,
10 | vars,
11 | group_vars = character(),
12 | .keep_all = FALSE,
13 | caller_env = caller_env(2),
14 | error_call = caller_env()
15 | )
16 |
17 | group_by_prepare(
18 | .data,
19 | ...,
20 | .add = FALSE,
21 | .dots = deprecated(),
22 | add = deprecated(),
23 | error_call = caller_env()
24 | )
25 | }
26 | \value{
27 | A list
28 | \item{data}{Modified tbl}
29 | \item{groups}{Modified groups}
30 | }
31 | \description{
32 | \verb{*_prepare()} performs standard manipulation that is needed prior
33 | to actual data processing. They are only be needed by packages
34 | that implement dplyr backends.
35 | }
36 | \keyword{internal}
37 |
--------------------------------------------------------------------------------
/man/group_cols.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/select-helpers.R
3 | \name{group_cols}
4 | \alias{group_cols}
5 | \title{Select grouping variables}
6 | \usage{
7 | group_cols(vars = NULL, data = NULL)
8 | }
9 | \arguments{
10 | \item{vars}{Deprecated; please use data instead.}
11 |
12 | \item{data}{For advanced use only. The default \code{NULL} automatically
13 | finds the "current" data frames.}
14 | }
15 | \description{
16 | This selection helpers matches grouping variables. It can be used
17 | in \code{\link[=select]{select()}} or \code{\link[=vars]{vars()}} selections.
18 | }
19 | \examples{
20 | gdf <- iris \%>\% group_by(Species)
21 | gdf \%>\% select(group_cols())
22 |
23 | # Remove the grouping variables from mutate selections:
24 | gdf \%>\% mutate_at(vars(-group_cols()), `/`, 100)
25 | # -> No longer necessary with across()
26 | gdf \%>\% mutate(across(everything(), ~ . / 100))
27 | }
28 | \seealso{
29 | \code{\link[=groups]{groups()}} and \code{\link[=group_vars]{group_vars()}} for retrieving the grouping
30 | variables outside selection contexts.
31 | }
32 |
--------------------------------------------------------------------------------
/man/group_trim.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/group-trim.R
3 | \name{group_trim}
4 | \alias{group_trim}
5 | \title{Trim grouping structure}
6 | \usage{
7 | group_trim(.tbl, .drop = group_by_drop_default(.tbl))
8 | }
9 | \arguments{
10 | \item{.tbl}{A \link[=grouped_df]{grouped data frame}}
11 |
12 | \item{.drop}{See \code{\link[=group_by]{group_by()}}}
13 | }
14 | \value{
15 | A \link[=grouped_df]{grouped data frame}
16 | }
17 | \description{
18 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
19 | Drop unused levels of all factors that are used as grouping variables,
20 | then recalculates the grouping structure.
21 |
22 | \code{group_trim()} is particularly useful after a \code{\link[=filter]{filter()}} that is intended
23 | to select a subset of groups.
24 | }
25 | \examples{
26 | iris \%>\%
27 | group_by(Species) \%>\%
28 | filter(Species == "setosa", .preserve = TRUE) \%>\%
29 | group_trim()
30 | }
31 | \seealso{
32 | Other grouping functions:
33 | \code{\link{group_by}()},
34 | \code{\link{group_map}()},
35 | \code{\link{group_nest}()},
36 | \code{\link{group_split}()}
37 | }
38 | \concept{grouping functions}
39 |
--------------------------------------------------------------------------------
/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 = group_by_drop_default(data))
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.}
19 |
20 | \item{drop}{When \code{.drop = TRUE}, empty groups are dropped.}
21 | }
22 | \description{
23 | The easiest way to create a grouped data frame is to call the \code{group_by()}
24 | method on a data frame or tbl: this will take care of capturing
25 | the unevaluated expressions for you.
26 |
27 | These functions are designed for programmatic use. For data analysis
28 | purposes see \code{\link[=group_data]{group_data()}} for the accessor functions that retrieve
29 | various metadata from a grouped data frames.
30 | }
31 | \keyword{internal}
32 |
--------------------------------------------------------------------------------
/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 strings and turns them as database identifiers (e.g. table
14 | or column names) quoting them using the identifer rules for your database.
15 | \code{ident_q()} does the same, but assumes the names have already been
16 | quoted, preventing them from being quoted again.
17 |
18 | These are generally for internal use only; if you need to supply an
19 | table name that is qualified with schema or catalog, or has already been
20 | quoted for some other reason, use \code{I()}.
21 | }
22 | \examples{
23 | # Identifiers are escaped with "
24 | \dontshow{if (requireNamespace("dbplyr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
25 | ident("x")
26 | \dontshow{\}) # examplesIf}
27 | }
28 |
--------------------------------------------------------------------------------
/man/last_dplyr_warnings.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/conditions.R
3 | \name{last_dplyr_warnings}
4 | \alias{last_dplyr_warnings}
5 | \title{Show warnings from the last command}
6 | \usage{
7 | last_dplyr_warnings(n = 5)
8 | }
9 | \arguments{
10 | \item{n}{Passed to \code{\link[=head]{head()}} so that only the first \code{n} warnings are
11 | displayed.}
12 | }
13 | \description{
14 | Warnings that occur inside a dplyr verb like \code{mutate()} are caught
15 | and stashed away instead of being emitted to the console. This
16 | prevents rowwise and grouped data frames from flooding the console
17 | with warnings. To see the original warnings, use
18 | \code{last_dplyr_warnings()}.
19 | }
20 | \keyword{internal}
21 |
--------------------------------------------------------------------------------
/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{lag}
6 | \alias{lead}
7 | \title{Compute lagged or leading values}
8 | \usage{
9 | lag(x, n = 1L, default = NULL, order_by = NULL, ...)
10 |
11 | lead(x, n = 1L, default = NULL, order_by = NULL, ...)
12 | }
13 | \arguments{
14 | \item{x}{A vector}
15 |
16 | \item{n}{Positive integer of length 1, giving the number of positions to
17 | lag or lead by}
18 |
19 | \item{default}{The value used to pad \code{x} back to its original size after the
20 | lag or lead has been applied. The default, \code{NULL}, pads with a missing
21 | value. If supplied, this must be a vector with size 1, which will be cast
22 | to the type of \code{x}.}
23 |
24 | \item{order_by}{An optional secondary vector that defines the ordering to use
25 | when applying the lag or lead to \code{x}. If supplied, this must be the same
26 | size as \code{x}.}
27 |
28 | \item{...}{Not used.}
29 | }
30 | \value{
31 | A vector with the same type and size as \code{x}.
32 | }
33 | \description{
34 | Find the "previous" (\code{lag()}) or "next" (\code{lead()}) values in a vector. Useful
35 | for comparing values behind of or ahead of the current values.
36 | }
37 | \examples{
38 | lag(1:5)
39 | lead(1:5)
40 |
41 | x <- 1:5
42 | tibble(behind = lag(x), x, ahead = lead(x))
43 |
44 | # If you want to look more rows behind or ahead, use `n`
45 | lag(1:5, n = 1)
46 | lag(1:5, n = 2)
47 |
48 | lead(1:5, n = 1)
49 | lead(1:5, n = 2)
50 |
51 | # If you want to define a value to pad with, use `default`
52 | lag(1:5)
53 | lag(1:5, default = 0)
54 |
55 | lead(1:5)
56 | lead(1:5, default = 6)
57 |
58 | # If the data are not already ordered, use `order_by`
59 | scrambled <- slice_sample(
60 | tibble(year = 2000:2005, value = (0:5) ^ 2),
61 | prop = 1
62 | )
63 |
64 | wrong <- mutate(scrambled, previous_year_value = lag(value))
65 | arrange(wrong, year)
66 |
67 | right <- mutate(scrambled, previous_year_value = lag(value, order_by = year))
68 | arrange(right, year)
69 | }
70 |
--------------------------------------------------------------------------------
/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 | \description{
18 | \code{tbl()} is the standard constructor for tbls. \code{as.tbl()} coerces,
19 | and \code{is.tbl()} tests.
20 | }
21 | \keyword{internal}
22 |
--------------------------------------------------------------------------------
/man/n_distinct.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/n-distinct.R
3 | \name{n_distinct}
4 | \alias{n_distinct}
5 | \title{Count unique combinations}
6 | \usage{
7 | n_distinct(..., na.rm = FALSE)
8 | }
9 | \arguments{
10 | \item{...}{Unnamed vectors. If multiple vectors are supplied, then they should
11 | have the same length.}
12 |
13 | \item{na.rm}{If \code{TRUE}, exclude missing observations from the count.
14 | If there are multiple vectors in \code{...}, an observation will
15 | be excluded if \emph{any} of the values are missing.}
16 | }
17 | \value{
18 | A single number.
19 | }
20 | \description{
21 | \code{n_distinct()} counts the number of unique/distinct combinations in a set
22 | of one or more vectors. It's a faster and more concise equivalent to
23 | \code{nrow(unique(data.frame(...)))}.
24 | }
25 | \examples{
26 | x <- c(1, 1, 2, 2, 2)
27 | n_distinct(x)
28 |
29 | y <- c(3, 3, NA, 3, 3)
30 | n_distinct(y)
31 | n_distinct(y, na.rm = TRUE)
32 |
33 | # Pairs (1, 3), (2, 3), and (2, NA) are distinct
34 | n_distinct(x, y)
35 |
36 | # (2, NA) is dropped, leaving 2 distinct combinations
37 | n_distinct(x, y, na.rm = TRUE)
38 |
39 | # Also works with data frames
40 | n_distinct(data.frame(x, y))
41 | }
42 |
--------------------------------------------------------------------------------
/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 \code{NA}}
6 | \usage{
7 | na_if(x, y)
8 | }
9 | \arguments{
10 | \item{x}{Vector to modify}
11 |
12 | \item{y}{Value or vector to compare against. When \code{x} and \code{y} are equal, the
13 | value in \code{x} will be replaced with \code{NA}.
14 |
15 | \code{y} is \link[vctrs:theory-faq-coercion]{cast} to the type of \code{x} before
16 | comparison.
17 |
18 | \code{y} is \link[vctrs:theory-faq-recycling]{recycled} to the size of \code{x} before
19 | comparison. This means that \code{y} can be a vector with the same size as \code{x},
20 | but most of the time this will be a single value.}
21 | }
22 | \value{
23 | A modified version of \code{x} that replaces any values that
24 | are equal to \code{y} with \code{NA}.
25 | }
26 | \description{
27 | This is a translation of the SQL command \code{NULLIF}. It is useful if you want
28 | to convert an annoying value to \code{NA}.
29 | }
30 | \examples{
31 | na_if(1:5, 5:1)
32 |
33 | x <- c(1, -1, 0, 10)
34 | 100 / x
35 | 100 / na_if(x, 0)
36 |
37 | y <- c("abc", "def", "", "ghi")
38 | na_if(y, "")
39 |
40 | # `na_if()` allows you to replace `NaN` with `NA`,
41 | # even though `NaN == NaN` returns `NA`
42 | z <- c(1, NaN, NA, 2, NaN)
43 | na_if(z, NaN)
44 |
45 | # `na_if()` is particularly useful inside `mutate()`,
46 | # and is meant for use with vectors rather than entire data frames
47 | starwars \%>\%
48 | select(name, eye_color) \%>\%
49 | mutate(eye_color = na_if(eye_color, "unknown"))
50 |
51 | # `na_if()` can also be used with `mutate()` and `across()`
52 | # to alter multiple columns
53 | starwars \%>\%
54 | mutate(across(where(is.character), ~na_if(., "unknown")))
55 | }
56 | \seealso{
57 | \code{\link[=coalesce]{coalesce()}} to replace missing values with a specified
58 | value.
59 |
60 | \code{\link[tidyr:replace_na]{tidyr::replace_na()}} to replace \code{NA} with a value.
61 | }
62 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/man/new_grouped_df.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/grouped-df.R, R/rowwise.R
3 | \name{new_grouped_df}
4 | \alias{new_grouped_df}
5 | \alias{validate_grouped_df}
6 | \alias{new_rowwise_df}
7 | \alias{validate_rowwise_df}
8 | \title{Low-level construction and validation for the grouped_df and rowwise_df classes}
9 | \usage{
10 | new_grouped_df(x, groups, ..., class = character())
11 |
12 | validate_grouped_df(x, check_bounds = FALSE)
13 |
14 | new_rowwise_df(data, group_data = NULL, ..., class = character())
15 |
16 | validate_rowwise_df(x)
17 | }
18 | \arguments{
19 | \item{x}{A data frame}
20 |
21 | \item{groups}{The grouped structure, \code{groups} should be a data frame.
22 | Its last column should be called \code{.rows} and be
23 | a list of 1 based integer vectors that all are between 1 and the number of rows of \code{.data}.}
24 |
25 | \item{...}{additional attributes}
26 |
27 | \item{class}{additional class, will be prepended to canonical classes.}
28 |
29 | \item{check_bounds}{whether to check all indices for out of bounds problems in \code{grouped_df} objects}
30 | }
31 | \description{
32 | \code{new_grouped_df()} and \code{new_rowwise_df()} are constructors designed to be high-performance so only
33 | check types, not values. This means it is the caller's responsibility
34 | to create valid values, and hence this is for expert use only.
35 |
36 | \code{validate_grouped_df()} and \code{validate_rowwise_df()} validate the attributes
37 | of a \code{grouped_df} or a \code{rowwise_df}.
38 | }
39 | \examples{
40 | # 5 bootstrap samples
41 | tbl <- new_grouped_df(
42 | tibble(x = rnorm(10)),
43 | groups = tibble(".rows" := replicate(5, sample(1:10, replace = TRUE), simplify = FALSE))
44 | )
45 | # mean of each bootstrap sample
46 | summarise(tbl, x = mean(x))
47 |
48 | }
49 | \keyword{internal}
50 |
--------------------------------------------------------------------------------
/man/ntile.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/rank.R
3 | \name{ntile}
4 | \alias{ntile}
5 | \title{Bucket a numeric vector into \code{n} groups}
6 | \usage{
7 | ntile(x = row_number(), n)
8 | }
9 | \arguments{
10 | \item{x}{A vector to rank
11 |
12 | By default, the smallest values will get the smallest ranks. Use \code{\link[=desc]{desc()}}
13 | to reverse the direction so the largest values get the smallest ranks.
14 |
15 | Missing values will be given rank \code{NA}. Use \code{coalesce(x, Inf)} or
16 | \code{coalesce(x, -Inf)} if you want to treat them as the largest or smallest
17 | values respectively.
18 |
19 | To rank by multiple columns at once, supply a data frame.}
20 |
21 | \item{n}{Number of groups to bucket into}
22 | }
23 | \description{
24 | \code{ntile()} is a sort of very rough rank, which breaks the input vector into
25 | \code{n} buckets. If \code{length(x)} is not an integer multiple of \code{n}, the size of
26 | the buckets will differ by up to one, with larger buckets coming first.
27 |
28 | Unlike other ranking functions, \code{ntile()} ignores ties: it will create
29 | evenly sized buckets even if the same value of \code{x} ends up in different
30 | buckets.
31 | }
32 | \examples{
33 | x <- c(5, 1, 3, 2, 2, NA)
34 | ntile(x, 2)
35 | ntile(x, 4)
36 |
37 | # If the bucket sizes are uneven, the larger buckets come first
38 | ntile(1:8, 3)
39 |
40 | # Ties are ignored
41 | ntile(rep(1, 8), 3)
42 | }
43 | \seealso{
44 | Other ranking functions:
45 | \code{\link{percent_rank}()},
46 | \code{\link{row_number}()}
47 | }
48 | \concept{ranking functions}
49 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/man/percent_rank.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/rank.R
3 | \name{percent_rank}
4 | \alias{percent_rank}
5 | \alias{cume_dist}
6 | \title{Proportional ranking functions}
7 | \usage{
8 | percent_rank(x)
9 |
10 | cume_dist(x)
11 | }
12 | \arguments{
13 | \item{x}{A vector to rank
14 |
15 | By default, the smallest values will get the smallest ranks. Use \code{\link[=desc]{desc()}}
16 | to reverse the direction so the largest values get the smallest ranks.
17 |
18 | Missing values will be given rank \code{NA}. Use \code{coalesce(x, Inf)} or
19 | \code{coalesce(x, -Inf)} if you want to treat them as the largest or smallest
20 | values respectively.
21 |
22 | To rank by multiple columns at once, supply a data frame.}
23 | }
24 | \value{
25 | A numeric vector containing a proportion.
26 | }
27 | \description{
28 | These two ranking functions implement two slightly different ways to
29 | compute a percentile. For each \code{x_i} in \code{x}:
30 | \itemize{
31 | \item \code{cume_dist(x)} counts the total number of values less than
32 | or equal to \code{x_i}, and divides it by the number of observations.
33 | \item \code{percent_rank(x)} counts the total number of values less than
34 | \code{x_i}, and divides it by the number of observations minus 1.
35 | }
36 |
37 | In both cases, missing values are ignored when counting the number
38 | of observations.
39 | }
40 | \examples{
41 | x <- c(5, 1, 3, 2, 2)
42 |
43 | cume_dist(x)
44 | percent_rank(x)
45 |
46 | # You can understand what's going on by computing it by hand
47 | sapply(x, function(xi) sum(x <= xi) / length(x))
48 | sapply(x, function(xi) sum(x < xi) / (length(x) - 1))
49 | # The real computations are a little more complex in order to
50 | # correctly deal with missing values
51 | }
52 | \seealso{
53 | Other ranking functions:
54 | \code{\link{ntile}()},
55 | \code{\link{row_number}()}
56 | }
57 | \concept{ranking functions}
58 |
--------------------------------------------------------------------------------
/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 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
21 |
22 | This progress bar has been deprecated since providing progress bars is not
23 | the responsibility of dplyr. Instead, you might try the more powerful
24 | \href{https://github.com/r-lib/progress}{progress} package.
25 |
26 | This reference class represents a text progress bar displayed estimated
27 | time remaining. When finished, it displays the total duration. The
28 | automatic progress bar can be disabled by setting option
29 | \code{dplyr.show_progress} to \code{FALSE}.
30 | }
31 | \examples{
32 | p <- progress_estimated(3)
33 | p$tick()
34 | p$tick()
35 | p$tick()
36 |
37 | p <- progress_estimated(3)
38 | for (i in 1:3) p$pause(0.1)$tick()$print()
39 |
40 | p <- progress_estimated(3)
41 | p$tick()$print()$
42 | pause(1)$stop()
43 |
44 | # If min_time is set, progress bar not shown until that many
45 | # seconds have elapsed
46 | p <- progress_estimated(3, min_time = 3)
47 | for (i in 1:3) p$pause(0.1)$tick()$print()
48 |
49 | \dontrun{
50 | p <- progress_estimated(10, min_time = 3)
51 | for (i in 1:10) p$pause(0.5)$tick()$print()
52 | }
53 | }
54 | \keyword{internal}
55 |
--------------------------------------------------------------------------------
/man/reexports.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/reexport-magrittr.R, R/reexport-pillar.R,
3 | % R/reexport-tibble.R, R/select-helpers.R
4 | \docType{import}
5 | \name{reexports}
6 | \alias{reexports}
7 | \alias{\%>\%}
8 | \alias{type_sum}
9 | \alias{data_frame}
10 | \alias{as_data_frame}
11 | \alias{lst}
12 | \alias{add_row}
13 | \alias{tribble}
14 | \alias{tibble}
15 | \alias{as_tibble}
16 | \alias{view}
17 | \alias{contains}
18 | \alias{select_helpers}
19 | \alias{ends_with}
20 | \alias{everything}
21 | \alias{matches}
22 | \alias{num_range}
23 | \alias{one_of}
24 | \alias{starts_with}
25 | \alias{last_col}
26 | \alias{any_of}
27 | \alias{all_of}
28 | \alias{where}
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:pipe]{\%>\%}}}
37 |
38 | \item{pillar}{\code{\link[pillar]{type_sum}}}
39 |
40 | \item{tibble}{\code{\link[tibble]{add_row}}, \code{\link[tibble:deprecated]{as_data_frame}}, \code{\link[tibble]{as_tibble}}, \code{\link[tibble:deprecated]{data_frame}}, \code{\link[tibble]{lst}}, \code{\link[tibble]{tibble}}, \code{\link[tibble]{tribble}}, \code{\link[tibble]{view}}}
41 |
42 | \item{tidyselect}{\code{\link[tidyselect]{all_of}}, \code{\link[tidyselect:all_of]{any_of}}, \code{\link[tidyselect:starts_with]{contains}}, \code{\link[tidyselect:starts_with]{ends_with}}, \code{\link[tidyselect]{everything}}, \code{\link[tidyselect:everything]{last_col}}, \code{\link[tidyselect:starts_with]{matches}}, \code{\link[tidyselect:starts_with]{num_range}}, \code{\link[tidyselect]{one_of}}, \code{\link[tidyselect]{starts_with}}, \code{\link[tidyselect]{where}}}
43 | }}
44 |
45 |
--------------------------------------------------------------------------------
/man/rmd/overview.Rmd:
--------------------------------------------------------------------------------
1 |
2 | Tidyverse selections implement a dialect of R where operators make
3 | it easy to select variables:
4 |
5 | - `:` for selecting a range of consecutive variables.
6 | - `!` for taking the complement of a set of variables.
7 | - `&` and `|` for selecting the intersection or the union of two
8 | sets of variables.
9 | - `c()` for combining selections.
10 |
11 | In addition, you can use __selection helpers__. Some helpers select specific
12 | columns:
13 |
14 | * [`everything()`][tidyselect::everything]: Matches all variables.
15 | * [`last_col()`][tidyselect::last_col]: Select last variable, possibly with an offset.
16 | * [group_cols()]: Select all grouping columns.
17 |
18 | Other helpers select variables by matching patterns in their names:
19 |
20 | * [`starts_with()`][tidyselect::starts_with]: Starts with a prefix.
21 | * [`ends_with()`][tidyselect::ends_with()]: Ends with a suffix.
22 | * [`contains()`][tidyselect::contains()]: Contains a literal string.
23 | * [`matches()`][tidyselect::matches()]: Matches a regular expression.
24 | * [`num_range()`][tidyselect::num_range()]: Matches a numerical range like x01, x02, x03.
25 |
26 | Or from variables stored in a character vector:
27 |
28 | * [`all_of()`][tidyselect::all_of()]: Matches variable names in a character vector. All
29 | names must be present, otherwise an out-of-bounds error is
30 | thrown.
31 | * [`any_of()`][tidyselect::any_of()]: Same as `all_of()`, except that no error is thrown
32 | for names that don't exist.
33 |
34 | Or using a predicate function:
35 |
36 | * [`where()`][tidyselect::where()]: Applies a function to all variables and selects those
37 | for which the function returns `TRUE`.
38 |
--------------------------------------------------------------------------------
/man/rmd/select.Rmd:
--------------------------------------------------------------------------------
1 | ```{r, include=FALSE}
2 | # So the second library() call doesn't show messages
3 | library(tidyverse)
4 | ```
5 |
6 | Here we show the usage for the basic selection operators. See the
7 | specific help pages to learn about helpers like [starts_with()].
8 |
9 | The selection language can be used in functions like
10 | `dplyr::select()` or `tidyr::pivot_longer()`. Let's first attach
11 | the tidyverse:
12 |
13 | ```{r}
14 | library(tidyverse)
15 |
16 | # For better printing
17 | iris <- as_tibble(iris)
18 | ```
19 |
20 | Select variables by name:
21 |
22 | ```{r}
23 | starwars %>% select(height)
24 |
25 | iris %>% pivot_longer(Sepal.Length)
26 | ```
27 |
28 | Select multiple variables by separating them with commas. Note how
29 | the order of columns is determined by the order of inputs:
30 |
31 | ```{r}
32 | starwars %>% select(homeworld, height, mass)
33 | ```
34 |
35 | Functions like `tidyr::pivot_longer()` don't take variables with
36 | dots. In this case use `c()` to select multiple variables:
37 |
38 | ```{r}
39 | iris %>% pivot_longer(c(Sepal.Length, Petal.Length))
40 | ```
41 |
42 | ## Operators:
43 |
44 | The `:` operator selects a range of consecutive variables:
45 |
46 | ```{r}
47 | starwars %>% select(name:mass)
48 | ```
49 |
50 | The `!` operator negates a selection:
51 |
52 | ```{r}
53 | starwars %>% select(!(name:mass))
54 |
55 | iris %>% select(!c(Sepal.Length, Petal.Length))
56 |
57 | iris %>% select(!ends_with("Width"))
58 | ```
59 |
60 | `&` and `|` take the intersection or the union of two selections:
61 |
62 | ```{r}
63 | iris %>% select(starts_with("Petal") & ends_with("Width"))
64 |
65 | iris %>% select(starts_with("Petal") | ends_with("Width"))
66 | ```
67 |
68 | To take the difference between two selections, combine the `&` and
69 | `!` operators:
70 |
71 | ```{r}
72 | iris %>% select(starts_with("Petal") & !ends_with("Width"))
73 | ```
74 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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:list2]{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 |
--------------------------------------------------------------------------------
/man/src_local.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/deprec-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 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
20 | This function was deprecated since it existed to support a style of testing
21 | dplyr backends that turned out not to be useful.
22 | }
23 | \keyword{internal}
24 |
--------------------------------------------------------------------------------
/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 | \item{...}{other arguments passed on to the individual methods.}
13 | }
14 | \description{
15 | This is a generic method which individual src's will provide methods for.
16 | Most methods will not be documented because it's usually pretty obvious what
17 | possible results will be.
18 | }
19 | \keyword{internal}
20 |
--------------------------------------------------------------------------------
/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{
8 | A tibble with 87 rows and 14 variables:
9 | \describe{
10 | \item{name}{Name of the character}
11 | \item{height}{Height (cm)}
12 | \item{mass}{Weight (kg)}
13 | \item{hair_color,skin_color,eye_color}{Hair, skin, and eye colors}
14 | \item{birth_year}{Year born (BBY = Before Battle of Yavin)}
15 | \item{sex}{The biological sex of the character, namely male, female, hermaphroditic, or none (as in the case for Droids).}
16 | \item{gender}{The gender role or gender identity of the character as determined by their personality or the way they were programmed (as in the case for Droids).}
17 | \item{homeworld}{Name of homeworld}
18 | \item{species}{Name of species}
19 | \item{films}{List of films the character appeared in}
20 | \item{vehicles}{List of vehicles the character has piloted}
21 | \item{starships}{List of starships the character has piloted}
22 | }
23 | }
24 | \usage{
25 | starwars
26 | }
27 | \description{
28 | The original data, from SWAPI, the Star Wars API, \url{https://swapi.py4e.com/}, has been revised
29 | to reflect additional research into gender and sex determinations of characters.
30 | }
31 | \examples{
32 | starwars
33 | }
34 | \keyword{datasets}
35 |
--------------------------------------------------------------------------------
/man/summarise_each.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/deprec-lazyeval.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 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
26 |
27 | \code{mutate_each()} and \code{summarise_each()} are deprecated in favour of
28 | the new \code{\link[=across]{across()}} function that works within \code{summarise()} and \code{mutate()}.
29 | }
30 | \keyword{internal}
31 |
--------------------------------------------------------------------------------
/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 | \title{Create a table from a data source}
7 | \usage{
8 | tbl(src, ...)
9 |
10 | is.tbl(x)
11 | }
12 | \arguments{
13 | \item{src}{A data source}
14 |
15 | \item{...}{Other arguments passed on to the individual methods}
16 |
17 | \item{x}{Any object}
18 | }
19 | \description{
20 | This is a generic method that dispatches based on the first argument.
21 | }
22 |
--------------------------------------------------------------------------------
/man/tbl_df.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/deprec-tibble.R
3 | \name{tbl_df}
4 | \alias{tbl_df}
5 | \alias{as.tbl}
6 | \title{Coerce to a tibble}
7 | \usage{
8 | tbl_df(data)
9 |
10 | as.tbl(x, ...)
11 | }
12 | \arguments{
13 | \item{data, x}{Object to coerce}
14 | }
15 | \description{
16 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
17 | Please use \code{\link[tibble:as_tibble]{tibble::as_tibble()}} instead.
18 | }
19 | \keyword{internal}
20 |
--------------------------------------------------------------------------------
/man/tbl_ptype.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/colwise.R
3 | \name{tbl_ptype}
4 | \alias{tbl_ptype}
5 | \title{Return a prototype of a tbl}
6 | \usage{
7 | tbl_ptype(.data)
8 | }
9 | \description{
10 | Used in \verb{_if} functions to enable type-based selection even when the data
11 | is lazily generated. Should either return the complete tibble, or if that
12 | can not be computed quickly, a 0-row tibble where the columns are of
13 | the correct type.
14 | }
15 | \keyword{internal}
16 |
--------------------------------------------------------------------------------
/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. The \code{groups} attribute
18 | of the object returned by \code{tbl_vars()} is a character vector of the
19 | grouping columns.
20 | }
21 | \seealso{
22 | \code{\link[=group_vars]{group_vars()}} for a function that returns grouping
23 | variables.
24 | }
25 | \keyword{internal}
26 |
--------------------------------------------------------------------------------
/man/tidyeval-compat.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/utils-tidy-eval.R
3 | \name{tidyeval-compat}
4 | \alias{tidyeval-compat}
5 | \alias{.data}
6 | \alias{expr}
7 | \alias{enquo}
8 | \alias{enquos}
9 | \alias{sym}
10 | \alias{syms}
11 | \alias{as_label}
12 | \alias{quo}
13 | \alias{quos}
14 | \alias{quo_name}
15 | \alias{ensym}
16 | \alias{ensyms}
17 | \alias{enexpr}
18 | \alias{enexprs}
19 | \title{Other tidy eval tools}
20 | \description{
21 | These tidy eval functions are no longer for normal usage, but are still
22 | exported from dplyr for backward compatibility.
23 | See \code{\link[rlang:args_data_masking]{?rlang::args_data_masking}} and
24 | \code{vignette("programming")} for the latest recommendations.
25 | \itemize{
26 | \item \link[rlang:expr]{expr()}
27 | \item \link[rlang:enquo]{enquo()}
28 | \item \link[rlang:enquo]{enquos()}
29 | \item \link[rlang:sym]{sym()}
30 | \item \link[rlang:sym]{syms()}
31 | \item \link[rlang:as_label]{as_label()}
32 | \item \link[rlang:defusing-advanced]{quo()}
33 | \item \link[rlang:defusing-advanced]{quos()}
34 | \item \link[rlang:quo_label]{quo_name()}
35 | \item \link[rlang:defusing-advanced]{ensym()}
36 | \item \link[rlang:defusing-advanced]{ensyms()}
37 | \item \link[rlang:defusing-advanced]{enexpr()}
38 | \item \link[rlang:defusing-advanced]{enexprs()}
39 | }
40 | }
41 | \keyword{internal}
42 |
--------------------------------------------------------------------------------
/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{...}{<\code{\link[=dplyr_tidy_select]{tidy-select}}> Variables to operate on.}
11 | }
12 | \description{
13 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}
14 |
15 | \code{vars()} is superseded because it is only needed for the scoped verbs (i.e.
16 | \code{\link[=mutate_at]{mutate_at()}}, \code{\link[=summarise_at]{summarise_at()}}, and friends), which have been been
17 | superseded in favour of \code{\link[=across]{across()}}. See \code{vignette("colwise")} for details.
18 |
19 | This helper is intended to provide tidy-select semantics for scoped verbs
20 | like \code{mutate_at()} and \code{summarise_at()}. Note that anywhere you can supply
21 | \code{vars()} specification, you can also supply a numeric vector of column
22 | positions or a character vector of column names.
23 | }
24 | \seealso{
25 | \code{\link[=all_vars]{all_vars()}} and \code{\link[=any_vars]{any_vars()}} for other quoting
26 | functions that you can use with scoped verbs.
27 | }
28 |
--------------------------------------------------------------------------------
/man/with_groups.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/groups-with.R
3 | \name{with_groups}
4 | \alias{with_groups}
5 | \title{Perform an operation with temporary groups}
6 | \usage{
7 | with_groups(.data, .groups, .f, ...)
8 | }
9 | \arguments{
10 | \item{.data}{A data frame}
11 |
12 | \item{.groups}{<\code{\link[=dplyr_tidy_select]{tidy-select}}> One or more variables
13 | to group by. Unlike \code{\link[=group_by]{group_by()}}, you can only group by existing variables,
14 | and you can use tidy-select syntax like \code{c(x, y, z)} to select multiple
15 | variables.
16 |
17 | Use \code{NULL} to temporarily \strong{un}group.}
18 |
19 | \item{.f}{Function to apply to regrouped data.
20 | Supports purrr-style \code{~} syntax}
21 |
22 | \item{...}{Additional arguments passed on to \code{...}.}
23 | }
24 | \description{
25 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}
26 |
27 | This was an experimental function that allows you to modify the grouping
28 | variables for a single operation; it is superseded in favour of using the
29 | \code{.by} argument to individual verbs.
30 | }
31 | \examples{
32 | df <- tibble(g = c(1, 1, 2, 2, 3), x = runif(5))
33 |
34 | # Old
35 | df \%>\%
36 | with_groups(g, mutate, x_mean = mean(x))
37 | # New
38 | df \%>\% mutate(x_mean = mean(x), .by = g)
39 | }
40 | \keyword{internal}
41 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-120x120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/pkgdown/favicon/apple-touch-icon-120x120.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-152x152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/pkgdown/favicon/apple-touch-icon-152x152.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-180x180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/pkgdown/favicon/apple-touch-icon-180x180.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-60x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/pkgdown/favicon/apple-touch-icon-60x60.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-76x76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/pkgdown/favicon/apple-touch-icon-76x76.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/pkgdown/favicon/apple-touch-icon.png
--------------------------------------------------------------------------------
/pkgdown/favicon/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/pkgdown/favicon/favicon-16x16.png
--------------------------------------------------------------------------------
/pkgdown/favicon/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/pkgdown/favicon/favicon-32x32.png
--------------------------------------------------------------------------------
/pkgdown/favicon/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tidyverse/dplyr/be3e3a05fd0081cb53168d6aedb417d62139b75d/pkgdown/favicon/favicon.ico
--------------------------------------------------------------------------------
/revdep/.gitignore:
--------------------------------------------------------------------------------
1 | checks
2 | library
3 | checks.noindex
4 | library.noindex
5 | data.sqlite
6 | *.html
7 | download
8 | lib
9 | cloud.noindex
10 |
--------------------------------------------------------------------------------
/revdep/drake-analyze.R:
--------------------------------------------------------------------------------
1 | library(tidyverse)
2 |
3 | all <- drake::readd(compare_all)
4 |
5 | error <- map_chr(map(all, class), 1) == "try-error"
6 |
7 | succeeded <- all[!error]
8 |
9 | withr::with_output_sink("revdep/new-problems.md", revdepcheck::revdep_report_problems(results = succeeded))
10 |
--------------------------------------------------------------------------------
/revdep/drake-base.R:
--------------------------------------------------------------------------------
1 | library(drake)
2 | library(tidyverse)
3 | library(glue)
4 |
5 | options(repos = revdepcheck:::get_repos(FALSE))
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 |
--------------------------------------------------------------------------------
/revdep/drake-deps.R:
--------------------------------------------------------------------------------
1 | source("revdep/drake-base.R")
2 |
3 | drake::make(plan_deps) %>% vis_drake_graph()
4 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/revdep/email.yml:
--------------------------------------------------------------------------------
1 | release_date: May 29
2 | rel_release_date: two weeks
3 | my_news_url: https://github.com/tidyverse/dplyr/blob/main/NEWS.md
4 | release_version: 1.0.0
5 | release_details: |
6 | We've pushed back the package release by two weeks, just to give everyone
7 | a little more time. Please see the recent blog post,
8 | ,
9 | for details of common problems and how to get help if you need it.
10 |
11 | Apologies if this email is repetitive; we don't currently have any way to
12 | track packages that are fixed on GitHub but not on CRAN.
13 |
--------------------------------------------------------------------------------
/revdep/new-problems.md:
--------------------------------------------------------------------------------
1 | # banR
2 |
3 | Version: 0.2.0
4 |
5 | ## Newly broken
6 |
7 | * checking re-building of vignette outputs ... WARNING
8 | ```
9 | Error in re-building vignettes:
10 | ...
11 | Warning in engine$weave(file, quiet = quiet, encoding = enc) :
12 | Pandoc (>= 1.12.3) and/or pandoc-citeproc not available. Falling back to R Markdown v1.
13 | Quitting from lines 47-49 (geocode.Rmd)
14 | Error: processing vignette 'geocode.Rmd' failed with diagnostics:
15 | The API sent back an error 503
16 | Execution halted
17 | ```
18 |
19 |
--------------------------------------------------------------------------------
/src/group_data.cpp:
--------------------------------------------------------------------------------
1 | #include "dplyr.h"
2 |
3 | SEXP dplyr_group_indices(SEXP data, SEXP rows) {
4 | R_xlen_t nr = vctrs::short_vec_size(data);
5 | if (nr == 0) {
6 | return dplyr::vectors::empty_int_vector;
7 | }
8 |
9 | SEXP indices = PROTECT(Rf_allocVector(INTSXP, nr));
10 | int* p_indices = INTEGER(indices);
11 | R_xlen_t ng = XLENGTH(rows);
12 | const SEXP* p_rows = VECTOR_PTR_RO(rows);
13 |
14 | for (R_xlen_t i = 0; i < ng; i++) {
15 | SEXP rows_i = p_rows[i];
16 | R_xlen_t n_i = XLENGTH(rows_i);
17 | int* p_rows_i = INTEGER(rows_i);
18 | for (R_xlen_t j = 0; j < n_i; j++, ++p_rows_i) {
19 | p_indices[*p_rows_i - 1] = i + 1;
20 | }
21 | }
22 | UNPROTECT(1);
23 | return indices;
24 | }
25 |
26 | SEXP dplyr_group_keys(SEXP group_data) {
27 | R_xlen_t n = XLENGTH(group_data) - 1;
28 | SEXP old_names = PROTECT(Rf_getAttrib(group_data, R_NamesSymbol));
29 | SEXP new_names = PROTECT(Rf_allocVector(STRSXP, n));
30 | SEXP keys = PROTECT(Rf_allocVector(VECSXP, n));
31 | const SEXP* p_old_names = STRING_PTR_RO(old_names);
32 | for (R_xlen_t i=0; i `a...1`
8 | * `b` -> `b...2`
9 | * `a` -> `a...3`
10 | * `b` -> `b...4`
11 |
12 | # bind_cols() handles unnamed list with name repair (#3402)
13 |
14 | Code
15 | df <- bind_cols(list(1, 2))
16 | Message
17 | New names:
18 | * `` -> `...1`
19 | * `` -> `...2`
20 |
21 | # bind_cols() gives informative errors
22 |
23 | Code
24 | # # incompatible size
25 | (expect_error(bind_cols(a = 1:2, mtcars)))
26 | Output
27 |
28 | Error in `bind_cols()`:
29 | ! Can't recycle `a` (size 2) to match `..2` (size 32).
30 | Code
31 | (expect_error(bind_cols(mtcars, a = 1:3)))
32 | Output
33 |
34 | Error in `bind_cols()`:
35 | ! Can't recycle `..1` (size 32) to match `a` (size 3).
36 |
37 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/bind-rows.md:
--------------------------------------------------------------------------------
1 | # bind_rows() only flattens S3 lists that inherit from list (#3924)
2 |
3 | Code
4 | bind_rows(lst1)
5 | Condition
6 | Error in `bind_rows()`:
7 | ! Argument 1 must be a data frame or a named atomic vector.
8 |
9 | # bind_rows() validates lists (#5417)
10 |
11 | Code
12 | bind_rows(list(x = 1), list(x = 1:3, y = 1:2))
13 | Condition
14 | Error in `vctrs::data_frame()`:
15 | ! Can't recycle `x` (size 3) to match `y` (size 2).
16 |
17 | # bind_rows() give informative errors
18 |
19 | Code
20 | # invalid .id
21 | df1 <- tibble(x = 1:3)
22 | df2 <- tibble(x = 4:6)
23 | (expect_error(bind_rows(df1, df2, .id = 5)))
24 | Output
25 |
26 | Error in `bind_rows()`:
27 | ! `.id` must be a single string, not the number 5.
28 | Code
29 | # invalid type
30 | ll <- list(tibble(a = 1:5), env(a = 1))
31 | (expect_error(bind_rows(ll)))
32 | Output
33 |
34 | Error in `bind_rows()`:
35 | ! Argument 2 must be a data frame or a named atomic vector.
36 | Code
37 | df1 <- tibble(a = factor("a"))
38 | df2 <- tibble(a = 1L)
39 | (expect_error(bind_rows(df1, df2)))
40 | Output
41 |
42 | Error in `bind_rows()`:
43 | ! Can't combine `..1$a` > and `..2$a` .
44 | Code
45 | # unnamed vectors
46 | (expect_error(bind_rows(1:2)))
47 | Output
48 |
49 | Error in `bind_rows()`:
50 | ! Argument 1 must be a data frame or a named atomic vector.
51 |
52 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/by.md:
--------------------------------------------------------------------------------
1 | # throws tidyselect errors
2 |
3 | Code
4 | compute_by(by = y, data = df)
5 | Condition
6 | Error:
7 | ! Can't select columns that don't exist.
8 | x Column `y` doesn't exist.
9 |
10 | # can't set `.by` with a grouped-df
11 |
12 | Code
13 | compute_by(x, gdf)
14 | Condition
15 | Error:
16 | ! Can't supply `by` when `data` is a grouped data frame.
17 |
18 | # can't set `.by` with a rowwise-df
19 |
20 | Code
21 | compute_by(x, rdf)
22 | Condition
23 | Error:
24 | ! Can't supply `by` when `data` is a rowwise data frame.
25 |
26 | # can tweak the error args
27 |
28 | Code
29 | compute_by(x, gdf, by_arg = "x", data_arg = "dat")
30 | Condition
31 | Error:
32 | ! Can't supply `x` when `dat` is a grouped data frame.
33 |
34 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/case-match.md:
--------------------------------------------------------------------------------
1 | # requires at least one condition
2 |
3 | Code
4 | case_match(1)
5 | Condition
6 | Error in `case_match()`:
7 | ! At least one condition must be supplied.
8 |
9 | ---
10 |
11 | Code
12 | case_match(1, NULL)
13 | Condition
14 | Error in `case_match()`:
15 | ! At least one condition must be supplied.
16 |
17 | # `.default` is part of common type computation
18 |
19 | Code
20 | case_match(1, 1 ~ 1L, .default = "x")
21 | Condition
22 | Error in `case_match()`:
23 | ! Can't combine `..1 (right)` and `.default` .
24 |
25 | # `NULL` formula element throws meaningful error
26 |
27 | Code
28 | case_match(1, 1 ~ NULL)
29 | Condition
30 | Error in `case_match()`:
31 | ! `..1 (right)` must be a vector, not `NULL`.
32 |
33 | ---
34 |
35 | Code
36 | case_match(1, NULL ~ 1)
37 | Condition
38 | Error in `case_match()`:
39 | ! `..1 (left)` must be a vector, not `NULL`.
40 |
41 | # throws chained errors when formula evaluation fails
42 |
43 | Code
44 | case_match(1, 1 ~ 2, 3 ~ stop("oh no!"))
45 | Condition
46 | Error in `case_match()`:
47 | ! Failed to evaluate the right-hand side of formula 2.
48 | Caused by error:
49 | ! oh no!
50 |
51 | ---
52 |
53 | Code
54 | case_match(1, 1 ~ 2, stop("oh no!") ~ 4)
55 | Condition
56 | Error in `case_match()`:
57 | ! Failed to evaluate the left-hand side of formula 2.
58 | Caused by error:
59 | ! oh no!
60 |
61 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/coalesce.md:
--------------------------------------------------------------------------------
1 | # coalesce() gives meaningful error messages
2 |
3 | Code
4 | (expect_error(coalesce(1:2, 1:3)))
5 | Output
6 |
7 | Error in `coalesce()`:
8 | ! Can't recycle `..1` (size 2) to match `..2` (size 3).
9 | Code
10 | (expect_error(coalesce(1:2, letters[1:2])))
11 | Output
12 |
13 | Error in `coalesce()`:
14 | ! Can't combine `..1` and `..2` .
15 |
16 | # `.size` overrides the common size
17 |
18 | Code
19 | coalesce(x, 1:2, .size = vec_size(x))
20 | Condition
21 | Error in `coalesce()`:
22 | ! Can't recycle `..2` (size 2) to size 1.
23 |
24 | # must have at least one non-`NULL` vector
25 |
26 | Code
27 | coalesce()
28 | Condition
29 | Error in `coalesce()`:
30 | ! `...` can't be empty.
31 |
32 | ---
33 |
34 | Code
35 | coalesce(NULL, NULL)
36 | Condition
37 | Error in `coalesce()`:
38 | ! `...` can't be empty.
39 |
40 | # inputs must be vectors
41 |
42 | Code
43 | coalesce(1, environment())
44 | Condition
45 | Error in `coalesce()`:
46 | ! `..2` must be a vector, not an environment.
47 |
48 | # names in error messages are indexed correctly
49 |
50 | Code
51 | coalesce(1, "x")
52 | Condition
53 | Error in `coalesce()`:
54 | ! Can't combine `..1` and `..2` .
55 |
56 | ---
57 |
58 | Code
59 | coalesce(1, y = "x")
60 | Condition
61 | Error in `coalesce()`:
62 | ! Can't combine `..1` and `y` .
63 |
64 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/colwise-filter.md:
--------------------------------------------------------------------------------
1 | # colwise filter() give meaningful errors
2 |
3 | Code
4 | (expect_error(filter_if(mtcars, is_character, all_vars(. > 0))))
5 | Output
6 |
7 | Error in `filter_if()`:
8 | ! `.predicate` must match at least one column.
9 | Code
10 | (expect_error(filter_all(mtcars, list(~ . > 0))))
11 | Output
12 |
13 | Error in `filter_all()`:
14 | ! `.vars_predicate` must be a function or a call to `all_vars()` or `any_vars()`, not a list.
15 |
16 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/colwise-select.md:
--------------------------------------------------------------------------------
1 | # colwise select() / rename() give meaningful errors
2 |
3 | Code
4 | df <- tibble(x = 0L, y = 0.5, z = 1)
5 | (expect_error(df %>% rename_all()))
6 | Output
7 |
8 | Error in `rename_all()`:
9 | ! `.funs` must specify a renaming function.
10 | Code
11 | (expect_error(df %>% rename_if(is_integerish)))
12 | Output
13 |
14 | Error in `rename_if()`:
15 | ! `.funs` must specify a renaming function.
16 | Code
17 | (expect_error(df %>% rename_at(vars(x:y))))
18 | Output
19 |
20 | Error in `rename_at()`:
21 | ! `.funs` must specify a renaming function.
22 | Code
23 | (expect_error(df %>% rename_all(list(tolower, toupper))))
24 | Output
25 |
26 | Error in `rename_all()`:
27 | ! `.funs` must contain one renaming function, not 2.
28 | Code
29 | (expect_error(df %>% select_all(list(tolower, toupper))))
30 | Output
31 |
32 | Error in `select_all()`:
33 | ! `.funs` must contain one renaming function, not 2.
34 | Code
35 | (expect_error(df %>% select_if(function(.x) 1)))
36 | Output
37 |
38 | Error in `select_if()`:
39 | ! `.p` is invalid.
40 | x `.p` should return a single logical.
41 | i `.p` returns a for column `x`.
42 | Code
43 | (expect_error(df %>% select_if(function(.x) c(TRUE, TRUE))))
44 | Output
45 |
46 | Error in `select_if()`:
47 | ! `.p` is invalid.
48 | x `.p` should return a single logical.
49 | i `.p` returns a size 2 for column `x`.
50 | Code
51 | (expect_error(data.frame() %>% select_all(.funs = 42)))
52 | Output
53 |
54 | Error in `select_all()`:
55 | ! `.funs` must be a one sided formula, a function, or a function name.
56 |
57 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/colwise.md:
--------------------------------------------------------------------------------
1 | # colwise utils gives meaningful error messages
2 |
3 | Code
4 | (expect_error(tbl_at_vars(iris, raw(3))))
5 | Output
6 |
7 | Error:
8 | ! `.vars` must be a character/numeric vector or a `vars()` object, not a raw vector.
9 | Code
10 | (expect_error(tbl_if_vars(iris, list(identity, force), environment())))
11 | Output
12 |
13 | Error:
14 | ! `.predicate` must have length 1, not 2.
15 | Code
16 | .funs <- as_fun_list(list(identity, force), caller_env())
17 | (expect_error(tbl_if_vars(iris, .funs, environment())))
18 | Output
19 |
20 | Error:
21 | ! `.predicate` must have length 1, not 2.
22 |
23 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/consecutive-id.md:
--------------------------------------------------------------------------------
1 | # follows recycling rules
2 |
3 | Code
4 | consecutive_id(1:3, 1:4)
5 | Condition
6 | Error in `consecutive_id()`:
7 | ! Can't recycle `..1` (size 3) to match `..2` (size 4).
8 |
9 | # generates useful errors
10 |
11 | Code
12 | consecutive_id(x = 1:4)
13 | Condition
14 | Error in `consecutive_id()`:
15 | ! Arguments in `...` must be passed by position, not name.
16 | x Problematic argument:
17 | * x = 1:4
18 | Code
19 | consecutive_id(mean)
20 | Condition
21 | Error in `consecutive_id()`:
22 | ! `..1` must be a vector, not a function.
23 |
24 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/context.md:
--------------------------------------------------------------------------------
1 | # give useful error messages when not applicable
2 |
3 | Code
4 | (expect_error(n()))
5 | Output
6 |
7 | Error in `n()`:
8 | ! Must only be used inside data-masking verbs like `mutate()`, `filter()`, and `group_by()`.
9 | Code
10 | (expect_error(cur_column()))
11 | Output
12 |
13 | Error in `cur_column()`:
14 | ! Must only be used inside `across()`.
15 | Code
16 | (expect_error(cur_group()))
17 | Output
18 |
19 | Error in `cur_group()`:
20 | ! Must only be used inside data-masking verbs like `mutate()`, `filter()`, and `group_by()`.
21 | Code
22 | (expect_error(cur_group_id()))
23 | Output
24 |
25 | Error in `cur_group_id()`:
26 | ! Must only be used inside data-masking verbs like `mutate()`, `filter()`, and `group_by()`.
27 | Code
28 | (expect_error(cur_group_rows()))
29 | Output
30 |
31 | Error in `cur_group_rows()`:
32 | ! Must only be used inside data-masking verbs like `mutate()`, `filter()`, and `group_by()`.
33 |
34 | # group labels are correctly formatted
35 |
36 | Code
37 | group_labels_details(c(a = 1))
38 | Output
39 | [1] "`a = 1`"
40 | Code
41 | group_labels_details(c(a = 1, b = 2))
42 | Output
43 | [1] "`a = 1`, `b = 2`"
44 |
45 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/copy-to.md:
--------------------------------------------------------------------------------
1 | # `auto_copy()` throws an informative error on different sources (#6798)
2 |
3 | Code
4 | auto_copy(df, NULL)
5 | Condition
6 | Error in `auto_copy()`:
7 | ! `x` and `y` must share the same src.
8 | i `x` is a object.
9 | i `y` is `NULL`.
10 | i Set `copy = TRUE` if `y` can be copied to the same source as `x` (may be slow).
11 |
12 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/deprec-combine.md:
--------------------------------------------------------------------------------
1 | # combine() is deprecated
2 |
3 | Code
4 | combine()
5 | Condition
6 | Warning:
7 | `combine()` was deprecated in dplyr 1.0.0.
8 | i Please use `vctrs::vec_c()` instead.
9 | Output
10 | logical(0)
11 |
12 | # combine() gives meaningful error messages
13 |
14 | Code
15 | (expect_error(combine("a", 1)))
16 | Output
17 |
18 | Error in `vec_c()`:
19 | ! Can't combine `..1` and `..2` .
20 | Code
21 | (expect_error(combine(factor("a"), 1L)))
22 | Output
23 |
24 | Error in `vec_c()`:
25 | ! Can't combine `..1` > and `..2` .
26 |
27 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/deprec-context.md:
--------------------------------------------------------------------------------
1 | # cur_data() is soft deprecated
2 |
3 | Code
4 | mutate(df, y = cur_data())
5 | Condition
6 | Warning:
7 | There was 1 warning in `mutate()`.
8 | i In argument: `y = cur_data()`.
9 | Caused by warning:
10 | ! `cur_data()` was deprecated in dplyr 1.1.0.
11 | i Please use `pick()` instead.
12 | Output
13 | # A tibble: 1 x 2
14 | x y$x
15 |
16 | 1 1 1
17 |
18 | # cur_data_all() is soft deprecated
19 |
20 | Code
21 | mutate(df, y = cur_data_all())
22 | Condition
23 | Warning:
24 | There was 1 warning in `mutate()`.
25 | i In argument: `y = cur_data_all()`.
26 | Caused by warning:
27 | ! `cur_data_all()` was deprecated in dplyr 1.1.0.
28 | i Please use `pick()` instead.
29 | Output
30 | # A tibble: 1 x 2
31 | x y$x
32 |
33 | 1 1 1
34 |
35 | # give useful error messages when not applicable
36 |
37 | Code
38 | (expect_error(cur_data()))
39 | Output
40 |
41 | Error in `cur_data()`:
42 | ! Must only be used inside data-masking verbs like `mutate()`, `filter()`, and `group_by()`.
43 | Code
44 | (expect_error(cur_data_all()))
45 | Output
46 |
47 | Error in `cur_data_all()`:
48 | ! Must only be used inside data-masking verbs like `mutate()`, `filter()`, and `group_by()`.
49 |
50 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/deprec-dbi.md:
--------------------------------------------------------------------------------
1 | # src_sqlite() gives meaningful error messages
2 |
3 | Code
4 | (expect_error(src_sqlite(":memory:")))
5 | Output
6 |
7 | Error in `src_sqlite()`:
8 | ! `path` must already exist, unless `create` = TRUE.
9 |
10 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/deprec-do.md:
--------------------------------------------------------------------------------
1 | # do() gives meaningful error messages
2 |
3 | Code
4 | (expect_error(df %>% do(head, tail)))
5 | Output
6 |
7 | Error in `do()`:
8 | ! Can only supply one unnamed argument, not 2.
9 | Code
10 | (expect_error(df %>% ungroup() %>% do(1)))
11 | Output
12 |
13 | Error in `do()`:
14 | ! Result must be a data frame, not numeric.
15 | Code
16 | (expect_error(df %>% do(1)))
17 | Output
18 |
19 | Error in `do()`:
20 | ! Results 1, 2, 3 must be data frames, not numeric.
21 | Code
22 | (expect_error(df %>% do("a")))
23 | Output
24 |
25 | Error in `do()`:
26 | ! Results 1, 2, 3 must be data frames, not character.
27 | Code
28 | (expect_error(df %>% do(x = 1, 2)))
29 | Output
30 |
31 | Error in `do()`:
32 | ! Arguments must either be all named or all unnamed.
33 |
34 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/deprec-funs.md:
--------------------------------------------------------------------------------
1 | # funs() is deprecated
2 |
3 | Code
4 | funs(fn = bar)
5 | Condition
6 | Warning:
7 | `funs()` was deprecated in dplyr 0.8.0.
8 | i Please use a list of either functions or lambdas:
9 |
10 | # Simple named list: list(mean = mean, median = median)
11 |
12 | # Auto named with `tibble::lst()`: tibble::lst(mean, median)
13 |
14 | # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
15 | Output
16 |
17 | $ fn: bar(.)
18 |
19 | # funs() give meaningful error messages
20 |
21 | Code
22 | (expect_error(funs(function(si) {
23 | mp[si]
24 | })))
25 | Output
26 |
27 | Error in `funs()`:
28 | ! `function(si) { mp[si] }` must be a function name (quoted or unquoted) or an unquoted call, not `function`.
29 | Code
30 | (expect_error(funs(~ mp[.])))
31 | Output
32 |
33 | Error in `funs()`:
34 | ! `~mp[.]` must be a function name (quoted or unquoted) or an unquoted call, not `~`.
35 |
36 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/deprec-lazyeval.md:
--------------------------------------------------------------------------------
1 | # mutate_each() and mutate_each_() are deprecated (#6869)
2 |
3 | Code
4 | mutate_each(df, list(~ .x + 1L))
5 | Condition
6 | Warning:
7 | `mutate_each()` was deprecated in dplyr 0.7.0.
8 | i Please use `across()` instead.
9 | Output
10 | # A tibble: 2 x 2
11 | x y
12 |
13 | 1 2 4
14 | 2 3 5
15 |
16 | ---
17 |
18 | Code
19 | mutate_each_(df, list(~ .x + 1L), c("x", "y"))
20 | Condition
21 | Warning:
22 | `mutate_each_()` was deprecated in dplyr 0.7.0.
23 | i Please use `across()` instead.
24 | Output
25 | # A tibble: 2 x 2
26 | x y
27 |
28 | 1 2 4
29 | 2 3 5
30 |
31 | # summarise_each() and summarise_each_() are deprecated (#6869)
32 |
33 | Code
34 | summarise_each(df, list(mean))
35 | Condition
36 | Warning:
37 | `summarise_each()` was deprecated in dplyr 0.7.0.
38 | i Please use `across()` instead.
39 | Output
40 | # A tibble: 1 x 2
41 | x y
42 |
43 | 1 1.5 3.5
44 |
45 | ---
46 |
47 | Code
48 | summarise_each_(df, list(mean), c("x", "y"))
49 | Condition
50 | Warning:
51 | `summarise_each_()` was deprecated in dplyr 0.7.0.
52 | i Please use `across()` instead.
53 | Output
54 | # A tibble: 1 x 2
55 | x y
56 |
57 | 1 1.5 3.5
58 |
59 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/deprec-src-local.md:
--------------------------------------------------------------------------------
1 | # src_df() is deprecated / errors
2 |
3 | Code
4 | (expect_error(src_df("base", new.env())))
5 | Output
6 |
7 | Error in `src_local()`:
8 | ! Exactly one of `pkg` and `env` must be non-NULL, not 2.
9 | Code
10 | (expect_error(src_df()))
11 | Output
12 |
13 | Error in `src_local()`:
14 | ! Exactly one of `pkg` and `env` must be non-NULL, not 0.
15 | Code
16 | env <- new.env(parent = emptyenv())
17 | env$x <- 1
18 | src_env <- src_df(env = env)
19 | (expect_error(copy_to(src_env, tibble(x = 1), name = "x")))
20 | Output
21 |
22 | Error in `copy_to()`:
23 | ! Object with `name` = `x` must not already exist, unless `overwrite` = TRUE.
24 |
25 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/desc.md:
--------------------------------------------------------------------------------
1 | # errors cleanly on non-vectors
2 |
3 | Code
4 | desc(mean)
5 | Condition
6 | Error in `desc()`:
7 | ! `x` must be a vector, not a function.
8 |
9 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/distinct.md:
--------------------------------------------------------------------------------
1 | # distinct errors when selecting an unknown column (#3140)
2 |
3 | Code
4 | df <- tibble(g = c(1, 2), x = c(1, 2))
5 | (expect_error(df %>% distinct(aa, x)))
6 | Output
7 |
8 | Error in `distinct()`:
9 | ! Must use existing variables.
10 | x `aa` not found in `.data`.
11 | Code
12 | (expect_error(df %>% distinct(aa, bb)))
13 | Output
14 |
15 | Error in `distinct()`:
16 | ! Must use existing variables.
17 | x `aa` not found in `.data`.
18 | x `bb` not found in `.data`.
19 | Code
20 | (expect_error(df %>% distinct(.data$aa)))
21 | Output
22 |
23 | Error in `distinct()`:
24 | ! Must use existing variables.
25 | x `aa` not found in `.data`.
26 | Code
27 | (expect_error(df %>% distinct(y = a + 1)))
28 | Output
29 |
30 | Error in `distinct()`:
31 | i In argument: `y = a + 1`.
32 | Caused by error:
33 | ! object 'a' not found
34 |
35 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/funs.md:
--------------------------------------------------------------------------------
1 | # takes the common type between all inputs (#6478)
2 |
3 | Code
4 | between("1", 2, 3)
5 | Condition
6 | Error in `between()`:
7 | ! Can't combine `x` and `left` .
8 |
9 | ---
10 |
11 | Code
12 | between(1, "2", 3)
13 | Condition
14 | Error in `between()`:
15 | ! Can't combine `x` and `left` .
16 |
17 | ---
18 |
19 | Code
20 | between(1, 2, "3")
21 | Condition
22 | Error in `between()`:
23 | ! Can't combine `x` and `right` .
24 |
25 | # recycles `left` and `right` to the size of `x`
26 |
27 | Code
28 | between(1:3, 1:2, 1L)
29 | Condition
30 | Error in `between()`:
31 | ! Can't recycle `left` (size 2) to size 3.
32 |
33 | ---
34 |
35 | Code
36 | between(1:3, 1L, 1:2)
37 | Condition
38 | Error in `between()`:
39 | ! Can't recycle `right` (size 2) to size 3.
40 |
41 | # ptype argument affects type casting
42 |
43 | Code
44 | between(x, 1.5, 3.5, ptype = integer())
45 | Condition
46 | Error in `between()`:
47 | ! Can't convert from `left` to due to loss of precision.
48 | * Locations: 1
49 |
50 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/group-by.md:
--------------------------------------------------------------------------------
1 | # can't rename while partially `ungroup()`-ing (#6606)
2 |
3 | Code
4 | ungroup(gdf, g2 = g)
5 | Condition
6 | Error in `ungroup()`:
7 | ! Can't rename variables in this context.
8 |
9 | # select(group_by(.)) implicitly adds grouping variables (#170)
10 |
11 | Code
12 | res <- mtcars %>% group_by(vs) %>% select(mpg)
13 | Message
14 | Adding missing grouping variables: `vs`
15 |
16 | # group_by works with zero-row data frames (#486)
17 |
18 | Code
19 | x <- select(dfg, a)
20 | Message
21 | Adding missing grouping variables: `g`
22 |
23 | # group_by() and ungroup() give meaningful error messages
24 |
25 | Code
26 | df <- tibble(x = 1, y = 2)
27 | (expect_error(df %>% group_by(unknown)))
28 | Output
29 |
30 | Error in `group_by()`:
31 | ! Must group by variables found in `.data`.
32 | x Column `unknown` is not found.
33 | Code
34 | (expect_error(df %>% ungroup(x)))
35 | Output
36 |
37 | Error in `ungroup()`:
38 | ! `...` must be empty.
39 | x Problematic argument:
40 | * ..1 = x
41 | i Did you forget to name an argument?
42 | Code
43 | (expect_error(df %>% group_by(x, y) %>% ungroup(z)))
44 | Output
45 |
46 | Error in `ungroup()`:
47 | ! Can't select columns that don't exist.
48 | x Column `z` doesn't exist.
49 | Code
50 | (expect_error(df %>% group_by(z = a + 1)))
51 | Output
52 |
53 | Error in `group_by()`:
54 | i In argument: `z = a + 1`.
55 | Caused by error:
56 | ! object 'a' not found
57 |
58 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/group-map.md:
--------------------------------------------------------------------------------
1 | # group_map() give meaningful errors
2 |
3 | Code
4 | (expect_error(mtcars %>% group_by(cyl) %>% group_modify(~ data.frame(cyl = 19)))
5 | )
6 | Output
7 |
8 | Error in `group_modify()`:
9 | ! The returned data frame cannot contain the original grouping variables: cyl.
10 | Code
11 | (expect_error(mtcars %>% group_by(cyl) %>% group_modify(~10)))
12 | Output
13 |
14 | Error in `group_modify()`:
15 | ! The result of `.f` must be a data frame.
16 | Code
17 | (expect_error(iris %>% group_by(Species) %>% group_modify(head1)))
18 | Output
19 |
20 | Error in `group_modify()`:
21 | ! `.f` must accept at least two arguments.
22 | i You can use `...` to absorb unused components.
23 | Code
24 | (expect_error(iris %>% group_by(Species) %>% group_map(head1)))
25 | Output
26 |
27 | Error in `group_map()`:
28 | ! `.f` must accept at least two arguments.
29 | i You can use `...` to absorb unused components.
30 |
31 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/if-else.md:
--------------------------------------------------------------------------------
1 | # takes the common type of `true` and `false` (#6243)
2 |
3 | Code
4 | if_else(TRUE, 1, "x")
5 | Condition
6 | Error in `if_else()`:
7 | ! Can't combine `true` and `false` .
8 |
9 | # includes `missing` in the common type computation if used
10 |
11 | Code
12 | if_else(TRUE, 1, 2, missing = "x")
13 | Condition
14 | Error in `if_else()`:
15 | ! Can't combine `true` and `missing` .
16 |
17 | # `condition` must be logical (and isn't cast to logical!)
18 |
19 | Code
20 | if_else(1:10, 1, 2)
21 | Condition
22 | Error in `if_else()`:
23 | ! `condition` must be a logical vector, not an integer vector.
24 |
25 | # `true`, `false`, and `missing` must recycle to the size of `condition`
26 |
27 | Code
28 | if_else(x < 2, bad, x)
29 | Condition
30 | Error in `if_else()`:
31 | ! `true` must have size 3, not size 2.
32 |
33 | ---
34 |
35 | Code
36 | if_else(x < 2, x, bad)
37 | Condition
38 | Error in `if_else()`:
39 | ! `false` must have size 3, not size 2.
40 |
41 | ---
42 |
43 | Code
44 | if_else(x < 2, x, x, missing = bad)
45 | Condition
46 | Error in `if_else()`:
47 | ! `missing` must have size 3, not size 2.
48 |
49 | # must have empty dots
50 |
51 | Code
52 | if_else(TRUE, 1, 2, missing = 3, 4)
53 | Condition
54 | Error in `if_else()`:
55 | ! `...` must be empty.
56 | x Problematic argument:
57 | * ..1 = 4
58 | i Did you forget to name an argument?
59 |
60 | # `ptype` overrides the common type
61 |
62 | Code
63 | if_else(TRUE, 1L, 2.5, ptype = integer())
64 | Condition
65 | Error in `if_else()`:
66 | ! Can't convert from `false` to due to loss of precision.
67 | * Locations: 1
68 |
69 | # `size` overrides the `condition` size
70 |
71 | Code
72 | if_else(TRUE, 1, 2, size = 2)
73 | Condition
74 | Error in `if_else()`:
75 | ! `condition` must have size 2, not size 1.
76 |
77 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/join-cross.md:
--------------------------------------------------------------------------------
1 | # cross join checks for duplicate names
2 |
3 | Code
4 | cross_join(df1, df2)
5 | Condition
6 | Error in `cross_join()`:
7 | ! Input columns in `x` must be unique.
8 | x Problem with `a`.
9 |
10 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/locale.md:
--------------------------------------------------------------------------------
1 | # `dplyr_legacy_locale()` respects `dplyr.legacy_locale`
2 |
3 | Code
4 | dplyr_legacy_locale()
5 | Condition
6 | Error:
7 | ! Global option `dplyr.legacy_locale` must be a single `TRUE` or `FALSE`.
8 |
9 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/n-distinct.md:
--------------------------------------------------------------------------------
1 | # n_distinct() generates useful errors
2 |
3 | Code
4 | n_distinct()
5 | Condition
6 | Error in `n_distinct()`:
7 | ! `...` is absent, but must be supplied.
8 | Code
9 | n_distinct(x = 1:4)
10 | Condition
11 | Error in `n_distinct()`:
12 | ! Arguments in `...` must be passed by position, not name.
13 | x Problematic argument:
14 | * x = 1:4
15 | Code
16 | n_distinct(mean)
17 | Condition
18 | Error in `n_distinct()`:
19 | ! `..1` must be a vector, not a function.
20 |
21 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/na-if.md:
--------------------------------------------------------------------------------
1 | # is type stable on `x`
2 |
3 | Code
4 | na_if(0L, 1.5)
5 | Condition
6 | Error in `na_if()`:
7 | ! Can't convert from `y` to `x` due to loss of precision.
8 | * Locations: 1
9 |
10 | # is size stable on `x`
11 |
12 | Code
13 | na_if(1, integer())
14 | Condition
15 | Error in `na_if()`:
16 | ! Can't recycle `y` (size 0) to size 1.
17 |
18 | ---
19 |
20 | Code
21 | na_if(1, c(1, 2))
22 | Condition
23 | Error in `na_if()`:
24 | ! Can't recycle `y` (size 2) to size 1.
25 |
26 | ---
27 |
28 | Code
29 | na_if(c(1, 2, 3), c(1, 2))
30 | Condition
31 | Error in `na_if()`:
32 | ! Can't recycle `y` (size 2) to size 3.
33 |
34 | # requires vector types for `x` and `y`
35 |
36 | Code
37 | na_if(environment(), 1)
38 | Condition
39 | Error in `na_if()`:
40 | ! `x` must be a vector, not an environment.
41 |
42 | ---
43 |
44 | Code
45 | na_if(1, environment())
46 | Condition
47 | Error in `na_if()`:
48 | ! `y` must be a vector, not an environment.
49 |
50 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/nth-value.md:
--------------------------------------------------------------------------------
1 | # `na_rm` is validated
2 |
3 | Code
4 | nth(1, 1, na_rm = 1)
5 | Condition
6 | Error in `nth()`:
7 | ! `na_rm` must be `TRUE` or `FALSE`, not the number 1.
8 |
9 | ---
10 |
11 | Code
12 | nth(1, 1, na_rm = c(TRUE, FALSE))
13 | Condition
14 | Error in `nth()`:
15 | ! `na_rm` must be `TRUE` or `FALSE`, not a logical vector.
16 |
17 | # `default` must be size 1 (when not used with lists)
18 |
19 | Code
20 | nth(1L, n = 2L, default = 1:2)
21 | Condition
22 | Error in `nth()`:
23 | ! `default` must have size 1, not size 2.
24 |
25 | # `default` is cast to the type of `x` (when not used with lists)
26 |
27 | Code
28 | nth("x", 2, default = 2)
29 | Condition
30 | Error in `nth()`:
31 | ! Can't convert `default` to match type of `x` .
32 |
33 | # `n` is validated (#5466)
34 |
35 | Code
36 | nth(1:10, n = "x")
37 | Condition
38 | Error in `nth()`:
39 | ! Can't convert `n` to .
40 |
41 | ---
42 |
43 | Code
44 | nth(1:10, n = 1:2)
45 | Condition
46 | Error in `nth()`:
47 | ! `n` must have size 1, not size 2.
48 |
49 | ---
50 |
51 | Code
52 | nth(1:10, n = NA_integer_)
53 | Condition
54 | Error in `nth()`:
55 | ! `n` can't be `NA`.
56 |
57 | # `x` must be a vector
58 |
59 | Code
60 | nth(environment(), 1L)
61 | Condition
62 | Error in `vec_size()`:
63 | ! `x` must be a vector, not an environment.
64 |
65 | # `order_by` must be the same size as `x`
66 |
67 | Code
68 | nth(1:5, n = 1L, order_by = 1:2)
69 | Condition
70 | Error in `nth()`:
71 | ! `order_by` must have size 5, not size 2.
72 |
73 | ---
74 |
75 | Code
76 | nth(1:5, n = 6L, order_by = 1:2)
77 | Condition
78 | Error in `nth()`:
79 | ! `order_by` must have size 5, not size 2.
80 |
81 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/order-by.md:
--------------------------------------------------------------------------------
1 | # order_by() gives useful error messages
2 |
3 | Code
4 | (expect_error(order_by(mtcars, 10)))
5 | Output
6 |
7 | Error in `order_by()`:
8 | ! `call` must be a function call, not the number 10.
9 | Code
10 | (expect_error(order_by(mtcars, cyl)))
11 | Output
12 |
13 | Error in `order_by()`:
14 | ! `call` must be a function call, not a symbol.
15 | i Did you mean `arrange(mtcars, cyl)`?
16 |
17 | # `with_order()` requires `order_by` and `x` to be the same size
18 |
19 | Code
20 | with_order(1:2, identity, 1:3)
21 | Condition
22 | Error in `with_order()`:
23 | ! `order_by` must have size 3, not size 2.
24 |
25 | # order_by() give meaningful errors
26 |
27 | Code
28 | (expect_error(order_by(NULL, 1L)))
29 | Output
30 |
31 | Error in `order_by()`:
32 | ! `call` must be a function call, not the number 1.
33 |
34 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/rank.md:
--------------------------------------------------------------------------------
1 | # ntile() validates `n`
2 |
3 | Code
4 | ntile(1, n = 1.5)
5 | Condition
6 | Error in `ntile()`:
7 | ! `n` must be a whole number, not the number 1.5.
8 |
9 | ---
10 |
11 | Code
12 | ntile(1, n = c(1, 2))
13 | Condition
14 | Error in `ntile()`:
15 | ! `n` must be a whole number, not a double vector.
16 |
17 | ---
18 |
19 | Code
20 | ntile(1, n = NA_real_)
21 | Condition
22 | Error in `ntile()`:
23 | ! `n` must be a whole number, not a numeric `NA`.
24 |
25 | ---
26 |
27 | Code
28 | ntile(1, n = 0)
29 | Condition
30 | Error in `ntile()`:
31 | ! `n` must be positive.
32 |
33 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/recode.md:
--------------------------------------------------------------------------------
1 | # `recode()` signals that it is superseded
2 |
3 | Code
4 | catch_cnd(recode("a", a = "A"))
5 | Output
6 |
8 |
9 | # `recode_factor()` signals that it is superseded
10 |
11 | Code
12 | catch_cnd(recode_factor("a", a = "A"))
13 | Output
14 |
16 |
17 | # recode() gives meaningful error messages
18 |
19 | Code
20 | (expect_error(recode(factor("a"), a = 5, .missing = 10)))
21 | Output
22 |
23 | Error in `recode()`:
24 | ! `.missing` is not supported for factors.
25 | Code
26 | (expect_error(recode("a", b = 5, "c")))
27 | Output
28 |
29 | Error in `recode()`:
30 | ! Argument 3 must be named.
31 | Code
32 | (expect_error(recode(factor("a"), b = 5, "c")))
33 | Output
34 |
35 | Error in `recode()`:
36 | ! Argument 3 must be named.
37 | Code
38 | (expect_error(recode(1:5)))
39 | Output
40 |
41 | Error in `recode()`:
42 | ! No replacements provided.
43 | Code
44 | (expect_error(recode("a")))
45 | Output
46 |
47 | Error in `recode()`:
48 | ! No replacements provided.
49 | Code
50 | (expect_error(recode(factor("a"))))
51 | Output
52 |
53 | Error in `recode()`:
54 | ! No replacements provided.
55 |
56 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/reframe.md:
--------------------------------------------------------------------------------
1 | # `reframe()` throws intelligent recycling errors
2 |
3 | Code
4 | reframe(df, x = 1:2, y = 3:5)
5 | Condition
6 | Error in `reframe()`:
7 | ! Can't recycle `y = 3:5`.
8 | Caused by error:
9 | ! `y` must be size 2 or 1, not 3.
10 | i An earlier column had size 2.
11 |
12 | ---
13 |
14 | Code
15 | reframe(df, x = 1:2, y = 3:5, .by = g)
16 | Condition
17 | Error in `reframe()`:
18 | ! Can't recycle `y = 3:5`.
19 | i In group 1: `g = 1`.
20 | Caused by error:
21 | ! `y` must be size 2 or 1, not 3.
22 | i An earlier column had size 2.
23 |
24 | ---
25 |
26 | Code
27 | reframe(gdf, x = 1:2, y = 3:5)
28 | Condition
29 | Error in `reframe()`:
30 | ! Can't recycle `y = 3:5`.
31 | i In group 1: `g = 1`.
32 | Caused by error:
33 | ! `y` must be size 2 or 1, not 3.
34 | i An earlier column had size 2.
35 |
36 | # `reframe()` doesn't message about regrouping when multiple group columns are supplied
37 |
38 | Code
39 | out <- reframe(df, x = mean(x), .by = c(a, b))
40 |
41 | ---
42 |
43 | Code
44 | out <- reframe(gdf, x = mean(x))
45 |
46 | # `reframe()` doesn't message about regrouping when >1 rows are returned per group
47 |
48 | Code
49 | out <- reframe(df, x = vec_rep_each(x, x), .by = g)
50 |
51 | ---
52 |
53 | Code
54 | out <- reframe(gdf, x = vec_rep_each(x, x))
55 |
56 | # catches `.by` with grouped-df
57 |
58 | Code
59 | reframe(gdf, .by = x)
60 | Condition
61 | Error in `reframe()`:
62 | ! Can't supply `.by` when `.data` is a grouped data frame.
63 |
64 | # catches `.by` with rowwise-df
65 |
66 | Code
67 | reframe(rdf, .by = x)
68 | Condition
69 | Error in `reframe()`:
70 | ! Can't supply `.by` when `.data` is a rowwise data frame.
71 |
72 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/relocate.md:
--------------------------------------------------------------------------------
1 | # can only supply one of .before and .after
2 |
3 | Code
4 | relocate(df, .before = 1, .after = 1)
5 | Condition
6 | Error in `relocate()`:
7 | ! Can't supply both `.before` and `.after`.
8 |
9 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/rename.md:
--------------------------------------------------------------------------------
1 | # `.fn` result type is checked (#6561)
2 |
3 | Code
4 | rename_with(df, fn)
5 | Condition
6 | Error in `rename_with()`:
7 | ! `.fn` must return a character vector, not an integer.
8 |
9 | # `.fn` result size is checked (#6561)
10 |
11 | Code
12 | rename_with(df, fn)
13 | Condition
14 | Error in `rename_with()`:
15 | ! `.fn` must return a vector of length 2, not 3.
16 |
17 | # can't rename in `.cols`
18 |
19 | Code
20 | rename_with(df, toupper, .cols = c(y = x))
21 | Condition
22 | Error in `rename_with()`:
23 | ! Can't rename variables in this context.
24 |
25 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/top-n.md:
--------------------------------------------------------------------------------
1 | # top_n() quotes n
2 |
3 | Code
4 | res1 <- top_n(mtcars, n() * 0.5)
5 | Message
6 | Selecting by carb
7 |
8 | ---
9 |
10 | Code
11 | res2 <- top_n(mtcars, 16)
12 | Message
13 | Selecting by carb
14 |
15 | # top_frac() is a shorthand for top_n(n()*)
16 |
17 | Code
18 | res1 <- top_n(mtcars, n() * 0.5)
19 | Message
20 | Selecting by carb
21 |
22 | ---
23 |
24 | Code
25 | res2 <- top_frac(mtcars, 0.5)
26 | Message
27 | Selecting by carb
28 |
29 |
--------------------------------------------------------------------------------
/tests/testthat/_snaps/transmute.md:
--------------------------------------------------------------------------------
1 | # transmute() error messages
2 |
3 | Code
4 | (expect_error(transmute(mtcars, cyl2 = cyl, .keep = "all")))
5 | Output
6 |
7 | Error in `transmute()`:
8 | ! The `.keep` argument is not supported.
9 | Code
10 | (expect_error(transmute(mtcars, cyl2 = cyl, .before = disp)))
11 | Output
12 |
13 | Error in `transmute()`:
14 | ! The `.before` argument is not supported.
15 | Code
16 | (expect_error(transmute(mtcars, cyl2 = cyl, .after = disp)))
17 | Output
18 |
19 | Error in `transmute()`:
20 | ! The `.after` argument is not supported.
21 |
22 |
--------------------------------------------------------------------------------
/tests/testthat/helper-dplyr.R:
--------------------------------------------------------------------------------
1 | expect_no_error <- function(object, ...) {
2 | expect_error({{ object }}, NA, ...)
3 | }
4 | expect_no_warning <- function(object, ...) {
5 | expect_warning({{ object }}, NA, ...)
6 | }
7 |
--------------------------------------------------------------------------------
/tests/testthat/helper-lazy.R:
--------------------------------------------------------------------------------
1 | skip_if_no_lazy_character <- function() {
2 | new_lazy_character <- import_vctrs("new_lazy_character", optional = TRUE)
3 | lazy_character_is_materialized <- import_vctrs(
4 | "lazy_character_is_materialized",
5 | optional = TRUE
6 | )
7 |
8 | if (is.null(new_lazy_character) || is.null(lazy_character_is_materialized)) {
9 | skip("Lazy character helpers from vctrs are not available.")
10 | }
11 |
12 | invisible()
13 | }
14 |
15 | new_lazy_character <- function(fn) {
16 | f <- import_vctrs("new_lazy_character")
17 | f(fn)
18 | }
19 |
20 | lazy_character_is_materialized <- function(x) {
21 | f <- import_vctrs("lazy_character_is_materialized")
22 | f(x)
23 | }
24 |
--------------------------------------------------------------------------------
/tests/testthat/helper-pick.R:
--------------------------------------------------------------------------------
1 | pick_wrapper <- function(...) {
2 | # Wrapping `pick()` forces evaluation fallback
3 | pick(...)
4 | }
5 |
--------------------------------------------------------------------------------
/tests/testthat/helper-s3.R:
--------------------------------------------------------------------------------
1 | local_methods <- function(..., .frame = caller_env()) {
2 | local_bindings(..., .env = global_env(), .frame = .frame)
3 | }
4 |
5 | local_foo_df <- function(frame = caller_env()) {
6 | local_methods(
7 | .frame = frame,
8 | group_by.foo_df = function(.data, ...) {
9 | out <- NextMethod()
10 | if (missing(...)) {
11 | class(out) <- c("foo_df", class(out))
12 | } else {
13 | class(out) <- c("grouped_foo_df", class(out))
14 | }
15 | out
16 | },
17 | ungroup.grouped_foo_df = function(x, ...) {
18 | out <- NextMethod()
19 | class(out) <- c("foo_df", class(out))
20 | out
21 | }
22 | )
23 | }
24 |
25 | new_ctor <- function(base_class) {
26 | function(x = list(), ..., class = NULL) {
27 | if (inherits(x, "tbl_df")) {
28 | tibble::new_tibble(x, class = c(class, base_class), nrow = nrow(x))
29 | } else if (is.data.frame(x)) {
30 | structure(x, class = c(class, base_class, "data.frame"), ...)
31 | } else {
32 | structure(x, class = c(class, base_class), ...)
33 | }
34 | }
35 | }
36 |
37 | foobar <- new_ctor("dplyr_foobar")
38 | foobaz <- new_ctor("dplyr_foobaz")
39 | quux <- new_ctor("dplyr_quux")
40 |
41 | # For testing reconstructing methods that break invariants by adding
42 | # new columns
43 | new_dispatched_quux <- function(x) {
44 | out <- quux(x)
45 | out$dispatched <- rep(TRUE, nrow(out))
46 | out
47 | }
48 |
--------------------------------------------------------------------------------
/tests/testthat/helper-torture.R:
--------------------------------------------------------------------------------
1 | with_gctorture2 <- withr::with_(gctorture2)
2 |
--------------------------------------------------------------------------------
/tests/testthat/test-case-match.R:
--------------------------------------------------------------------------------
1 | test_that("LHS can match multiple values", {
2 | expect_equal(case_match(1, 1:2 ~ "x"), "x")
3 | })
4 |
5 | test_that("LHS can match special values", {
6 | expect_equal(case_match(NA, NA ~ "x"), "x")
7 | expect_equal(case_match(NaN, NaN ~ "x"), "x")
8 | })
9 |
10 | test_that("RHS is recycled to match x", {
11 | x <- 1:3
12 | expect_equal(case_match(x, c(1, 3) ~ x * 2), c(2, NA, 6))
13 | })
14 |
15 | test_that("`NULL` values in `...` are dropped", {
16 | expect_identical(
17 | case_match(1:2, 1 ~ "a", NULL, 2 ~ "b", NULL),
18 | c("a", "b")
19 | )
20 | })
21 |
22 | test_that("requires at least one condition", {
23 | expect_snapshot(error = TRUE, {
24 | case_match(1)
25 | })
26 | expect_snapshot(error = TRUE, {
27 | case_match(1, NULL)
28 | })
29 | })
30 |
31 | test_that("passes through `.default` correctly", {
32 | expect_identical(case_match(1, 3 ~ 1, .default = 2), 2)
33 | expect_identical(case_match(1:5, 6 ~ 1, .default = 2), rep(2, 5))
34 | expect_identical(case_match(1:5, 6 ~ 1:5, .default = 2:6), 2:6)
35 | })
36 |
37 | test_that("`.default` is part of common type computation", {
38 | expect_identical(case_match(1, 1 ~ 1L, .default = 2), 1)
39 |
40 | expect_snapshot(error = TRUE, {
41 | case_match(1, 1 ~ 1L, .default = "x")
42 | })
43 | })
44 |
45 | test_that("passes through `.ptype` correctly", {
46 | expect_identical(case_match(1, 1 ~ 1, .ptype = integer()), 1L)
47 | })
48 |
49 | test_that("`NULL` formula element throws meaningful error", {
50 | expect_snapshot(error = TRUE, {
51 | case_match(1, 1 ~ NULL)
52 | })
53 | expect_snapshot(error = TRUE, {
54 | case_match(1, NULL ~ 1)
55 | })
56 | })
57 |
58 | test_that("throws chained errors when formula evaluation fails", {
59 | expect_snapshot(error = TRUE, {
60 | case_match(1, 1 ~ 2, 3 ~ stop("oh no!"))
61 | })
62 | expect_snapshot(error = TRUE, {
63 | case_match(1, 1 ~ 2, stop("oh no!") ~ 4)
64 | })
65 | })
66 |
--------------------------------------------------------------------------------
/tests/testthat/test-colwise-distinct.R:
--------------------------------------------------------------------------------
1 | test_that("scoped distinct is identical to manual distinct", {
2 | df <- tibble(
3 | x = rep(2:5, each = 2),
4 | y = rep(2:3, each = 4),
5 | z = "a"
6 | )
7 |
8 | expect_identical(distinct_all(df), distinct(df, x, y, z))
9 | expect_identical(distinct_at(df, vars(x)), distinct(df, x))
10 | expect_identical(distinct_if(df, is.integer), distinct(df, x, y))
11 | })
12 |
13 | test_that(".funs is applied to variables before getting distinct rows", {
14 | df <- tibble(
15 | x = rep(2:5, each = 2),
16 | y = rep(2:3, each = 4)
17 | )
18 |
19 | expect_identical(distinct_all(df, `-`), distinct(mutate_all(df, `-`), x, y))
20 | })
21 |
22 | test_that("scoped distinct applies to grouping variables (#3480)", {
23 | df <- tibble(
24 | g = rep(1:2, each = 4),
25 | x = rep(2:5, each = 2) / 2,
26 | y = rep(2:3, each = 4) / 2
27 | )
28 | out <- df[c(1, 3, 5, 8), ]
29 |
30 | expect_identical(distinct_all(df), out)
31 | expect_identical(distinct_at(df, vars(g, x, y)), out)
32 | expect_identical(distinct_if(df, is.numeric), out)
33 | })
34 |
--------------------------------------------------------------------------------
/tests/testthat/test-colwise-funs.R:
--------------------------------------------------------------------------------
1 | test_that("as_fun_list() uses rlang auto-naming", {
2 | nms <- names(as_fun_list(list(min, max), env()))
3 |
4 | # Just check they are labellised as literals enclosed in brackets to
5 | # insulate from upstream changes
6 | expect_true(all(grepl("^<", nms)))
7 | })
8 |
--------------------------------------------------------------------------------
/tests/testthat/test-colwise-group-by.R:
--------------------------------------------------------------------------------
1 | test_that("group_by_ verbs take scoped inputs", {
2 | expect_identical(group_vars(group_by_all(mtcars)), names(mtcars))
3 | expect_identical(
4 | group_vars(group_by_at(mtcars, vars(starts_with("d")))),
5 | c("disp", "drat")
6 | )
7 | expect_identical(group_vars(group_by_if(iris, is.factor)), "Species")
8 | })
9 |
10 | test_that("group_by_ verbs accept optional operations", {
11 | df <- tibble(x = 1:2, y = 2:3)
12 | gdf <- group_by(mutate_all(df, as.factor), x, y)
13 |
14 | expect_identical(group_by_all(df, as.factor), gdf)
15 | expect_identical(group_by_if(df, is_integer, as.factor), gdf)
16 | expect_identical(group_by_at(df, vars(x:y), as.factor), gdf)
17 | })
18 |
19 | test_that("group_by variants can group by an already grouped by data (#3351)", {
20 | tbl <- tibble(gr1 = rep(1:2, 4), gr2 = rep(c(1, 2), each = 4), x = 1:8) %>%
21 | group_by(gr1)
22 |
23 | expect_identical(
24 | group_by_at(tbl, vars(gr1, gr2)),
25 | group_by(tbl, gr1, gr2)
26 | )
27 |
28 | expect_identical(
29 | group_by_all(tbl),
30 | group_by(tbl, gr1, gr2, x)
31 | )
32 |
33 | expect_identical(
34 | group_by_if(tbl, is.integer),
35 | group_by(tbl, gr1, x)
36 | )
37 | })
38 |
--------------------------------------------------------------------------------
/tests/testthat/test-colwise.R:
--------------------------------------------------------------------------------
1 | test_that("tbl_at_vars() treats `NULL` as empty inputs", {
2 | expect_identical(tbl_at_vars(mtcars, vars(NULL)), tbl_at_vars(mtcars, vars()))
3 | expect_identical(
4 | tibble::remove_rownames(mutate_at(mtcars, vars(NULL), `*`, 100)),
5 | tibble::remove_rownames(mtcars)
6 | )
7 | })
8 |
9 | test_that("lists of formulas are auto-named", {
10 | df <- tibble(x = 1:3, y = 4:6)
11 |
12 | out <- df %>% summarise_all(list(~ mean(.), ~ sd(.x, na.rm = TRUE)))
13 | expect_named(out, c("x_mean", "y_mean", "x_sd", "y_sd"))
14 |
15 | out <- df %>% summarise_all(list(foobar = ~ mean(.), ~ sd(.x, na.rm = TRUE)))
16 | expect_named(out, c("x_foobar", "y_foobar", "x_sd", "y_sd"))
17 | })
18 |
19 | # Errors --------------------------------------------
20 |
21 | test_that("colwise utils gives meaningful error messages", {
22 | expect_snapshot({
23 | (expect_error(
24 | tbl_at_vars(iris, raw(3))
25 | ))
26 | (expect_error(
27 | tbl_if_vars(iris, list(identity, force), environment())
28 | ))
29 |
30 | .funs <- as_fun_list(list(identity, force), caller_env())
31 | (expect_error(
32 | tbl_if_vars(iris, .funs, environment())
33 | ))
34 | })
35 | })
36 |
--------------------------------------------------------------------------------
/tests/testthat/test-consecutive-id.R:
--------------------------------------------------------------------------------
1 | test_that("works with simple vectors", {
2 | expect_equal(consecutive_id(c(1, 1, 2, 1, 2)), c(1, 1, 2, 3, 4))
3 | })
4 |
5 | test_that("handles data frames", {
6 | df <- tibble(x = c(1, 1, 1, 1), y = c(1, 2, 2, 1))
7 | expect_equal(consecutive_id(df), c(1, 2, 2, 3))
8 | })
9 |
10 | test_that("follows recycling rules", {
11 | expect_equal(consecutive_id(double(), 1), integer())
12 | expect_equal(consecutive_id(1:2, 1), 1:2)
13 |
14 | expect_snapshot(error = TRUE, {
15 | consecutive_id(1:3, 1:4)
16 | })
17 | })
18 |
19 | test_that("generates useful errors", {
20 | expect_snapshot(error = TRUE, {
21 | consecutive_id(x = 1:4)
22 | consecutive_id(mean)
23 | })
24 | })
25 |
--------------------------------------------------------------------------------
/tests/testthat/test-context.R:
--------------------------------------------------------------------------------
1 | test_that("cur_group() works", {
2 | df <- tibble(g = 1, x = 1)
3 | gf <- group_by(df, g)
4 |
5 | expect_equal(
6 | df %>% summarise(key = list(cur_group())) %>% pull(key),
7 | list(tibble(.rows = 1L))
8 | )
9 | expect_equal(
10 | gf %>% summarise(key = list(cur_group())) %>% pull(key),
11 | list(tibble(g = 1))
12 | )
13 | })
14 |
15 | test_that("cur_group() works with empty grouped data frame (#6304)", {
16 | df <- tibble(x = integer())
17 | gdf <- group_by(df, x)
18 |
19 | out <- mutate(df, y = cur_group())
20 | expect_identical(out$y, tibble())
21 |
22 | out <- mutate(gdf, y = cur_group())
23 | expect_identical(out$y, tibble(x = integer()))
24 | })
25 |
26 | test_that("cur_group_idx() gives unique id", {
27 | df <- tibble(x = c("b", "a", "b"))
28 | gf <- group_by(df, x)
29 |
30 | expect_equal(
31 | summarise(gf, id = cur_group_id()),
32 | tibble(x = c("a", "b"), id = 1:2)
33 | )
34 | expect_equal(
35 | mutate(gf, id = cur_group_id()),
36 | group_by(tibble(x = df$x, id = c(2, 1, 2)), x)
37 | )
38 | })
39 |
40 | test_that("cur_group_rows() retrieves row position in original data", {
41 | df <- tibble(x = c("b", "a", "b"), y = 1:3)
42 | gf <- group_by(df, x)
43 |
44 | expect_equal(
45 | df %>% summarise(x = list(cur_group_rows())) %>% pull(),
46 | list(1:3)
47 | )
48 |
49 | expect_equal(
50 | gf %>% summarise(x = list(cur_group_rows())) %>% pull(),
51 | list(2L, c(1L, 3L))
52 | )
53 | })
54 |
55 | test_that("give useful error messages when not applicable", {
56 | expect_snapshot({
57 | (expect_error(n()))
58 |
59 | (expect_error(cur_column()))
60 | (expect_error(cur_group()))
61 | (expect_error(cur_group_id()))
62 | (expect_error(cur_group_rows()))
63 | })
64 | })
65 |
66 | test_that("group labels are correctly formatted", {
67 | expect_snapshot({
68 | group_labels_details(c("a" = 1))
69 | group_labels_details(c("a" = 1, "b" = 2))
70 | })
71 | })
72 |
--------------------------------------------------------------------------------
/tests/testthat/test-copy-to.R:
--------------------------------------------------------------------------------
1 | test_that("`auto_copy()` is a no-op when they share the same source", {
2 | df1 <- tibble(x = 1)
3 | df2 <- tibble(x = 2)
4 |
5 | expect_identical(auto_copy(df1, df2), df2)
6 | })
7 |
8 | test_that("`auto_copy()` throws an informative error on different sources (#6798)", {
9 | df <- tibble(x = 1)
10 |
11 | expect_snapshot(error = TRUE, {
12 | auto_copy(df, NULL)
13 | })
14 | })
15 |
--------------------------------------------------------------------------------
/tests/testthat/test-data-mask.R:
--------------------------------------------------------------------------------
1 | test_that("Empty matrix can be coerced to a data frame (#7004)", {
2 | skip_if_not(getRversion() >= "4.4")
3 | expect_equal(
4 | slice(as.data.frame(matrix(nrow = 0, ncol = 0)), 1),
5 | data.frame()
6 | )
7 | })
8 |
--------------------------------------------------------------------------------
/tests/testthat/test-defunct.R:
--------------------------------------------------------------------------------
1 | test_that("generate informative errors", {
2 | expect_snapshot(error = TRUE, {
3 | id()
4 |
5 | failwith()
6 |
7 | select_vars()
8 | rename_vars()
9 | select_var()
10 | current_vars()
11 |
12 | bench_tbls()
13 | compare_tbls()
14 | compare_tbls2()
15 | eval_tbls()
16 | eval_tbls2()
17 |
18 | location()
19 | changes()
20 | })
21 | })
22 |
--------------------------------------------------------------------------------
/tests/testthat/test-deprec-dbi.R:
--------------------------------------------------------------------------------
1 | test_that("src_sqlite() gives meaningful error messages", {
2 | skip_if_not_installed("dbplyr")
3 | withr::local_options(lifecycle_verbosity = "quiet")
4 |
5 | expect_snapshot({
6 | (expect_error(src_sqlite(":memory:")))
7 | })
8 | })
9 |
--------------------------------------------------------------------------------
/tests/testthat/test-deprec-src-local.R:
--------------------------------------------------------------------------------
1 | test_that("src_tbls() includes all tbls (#4326)", {
2 | withr::local_options(lifecycle_verbosity = "quiet")
3 |
4 | expect_equal(
5 | src_tbls(src_df(env = env(. = iris))),
6 | "."
7 | )
8 | })
9 |
10 | test_that("src_local only overwrites if overwrite = TRUE", {
11 | withr::local_options(lifecycle_verbosity = "quiet")
12 |
13 | env <- new.env(parent = emptyenv())
14 | env$x <- 1
15 |
16 | src_env <- src_df(env = env)
17 |
18 | df <- tibble(x = 1)
19 | copy_to(src_env, df, name = "x", overwrite = TRUE)
20 | expect_equal(env$x, df)
21 | })
22 |
23 | test_that("src_df() is deprecated / errors", {
24 | withr::local_options(lifecycle_verbosity = "quiet")
25 |
26 | expect_snapshot({
27 | # src_local errs with pkg/env
28 | (expect_error(src_df("base", new.env())))
29 | (expect_error(src_df()))
30 |
31 | env <- new.env(parent = emptyenv())
32 | env$x <- 1
33 | src_env <- src_df(env = env)
34 | (expect_error(
35 | copy_to(src_env, tibble(x = 1), name = "x")
36 | ))
37 | })
38 | })
39 |
--------------------------------------------------------------------------------
/tests/testthat/test-deprec-tibble.R:
--------------------------------------------------------------------------------
1 | test_that("add_rownames is deprecated", {
2 | expect_warning(
3 | res <- mtcars %>% add_rownames("Make&Model"),
4 | "deprecated"
5 | )
6 | expect_equal(class(res), c("tbl_df", "tbl", "data.frame"))
7 | })
8 |
--------------------------------------------------------------------------------
/tests/testthat/test-desc.R:
--------------------------------------------------------------------------------
1 | test_that("errors cleanly on non-vectors", {
2 | expect_snapshot(desc(mean), error = TRUE)
3 | })
4 |
--------------------------------------------------------------------------------
/tests/testthat/test-group-trim.R:
--------------------------------------------------------------------------------
1 | test_that("group_trim() is identity on non grouped data", {
2 | expect_identical(group_trim(iris), iris)
3 | })
4 |
5 | test_that("group_trim() always regroups even if no factors", {
6 | res <- mtcars %>%
7 | group_by(cyl) %>%
8 | filter(cyl == 6, .preserve = TRUE) %>%
9 | group_trim()
10 | expect_equal(n_groups(res), 1L)
11 | })
12 |
13 | test_that("group_trim() drops factor levels in data and grouping structure", {
14 | res <- iris %>%
15 | group_by(Species) %>%
16 | filter(Species == "setosa") %>%
17 | group_trim()
18 |
19 | expect_equal(n_groups(res), 1L)
20 | expect_equal(levels(res$Species), "setosa")
21 | expect_equal(levels(attr(res, "groups")$Species), "setosa")
22 | })
23 |
--------------------------------------------------------------------------------
/tests/testthat/test-groups-with.R:
--------------------------------------------------------------------------------
1 | test_that("restores original class", {
2 | df <- data.frame(x = 1:2)
3 | gf <- group_by(df, x)
4 |
5 | expect_s3_class(with_groups(df, x, mutate), "data.frame", exact = TRUE)
6 | expect_s3_class(with_groups(gf, x, mutate), "grouped_df")
7 | })
8 |
9 | test_that(".groups = NULL ungroups", {
10 | gf <- group_by(tibble(x = 1:2), x)
11 | out <- gf %>% with_groups(NULL, mutate, y = mean(x))
12 | expect_equal(out$y, c(1.5, 1.5))
13 | })
14 |
15 | test_that(".groups is defused with context", {
16 | local_fn <- identity
17 | expect_identical(
18 | with_groups(mtcars, local_fn(2), mutate, disp = disp / sd(disp)),
19 | with_groups(mtcars, 2, mutate, disp = disp / sd(disp))
20 | )
21 | })
22 |
--------------------------------------------------------------------------------
/tests/testthat/test-join-cross.R:
--------------------------------------------------------------------------------
1 | test_that("cross join works", {
2 | df1 <- tibble(x = 1:2)
3 | df2 <- tibble(y = 1:3)
4 |
5 | expect_identical(
6 | cross_join(df1, df2),
7 | tibble(
8 | x = vec_rep_each(1:2, times = 3),
9 | y = vec_rep(1:3, times = 2)
10 | )
11 | )
12 | })
13 |
14 | test_that("cross join results in 0 rows if either input has 0 rows", {
15 | df1 <- tibble(x = 1:2)
16 | df2 <- tibble(y = integer())
17 |
18 | expect_identical(
19 | cross_join(df1, df2),
20 | tibble(x = integer(), y = integer())
21 | )
22 | expect_identical(
23 | cross_join(df2, df1),
24 | tibble(y = integer(), x = integer())
25 | )
26 | })
27 |
28 | test_that("cross join works with 0 column, >0 row tibbles", {
29 | df1 <- new_tibble(list(), nrow = 3)
30 | df2 <- tibble(x = 1:2)
31 |
32 | expect_identical(
33 | cross_join(df1, df1),
34 | new_tibble(list(), nrow = 9)
35 | )
36 | expect_identical(
37 | cross_join(df1, df2),
38 | vec_rep(df2, times = 3)
39 | )
40 | })
41 |
42 | test_that("cross join applies `suffix`", {
43 | df1 <- tibble(x = 1, y = 2)
44 | df2 <- tibble(x = 2, z = 3)
45 |
46 | expect_named(cross_join(df1, df2), c("x.x", "y", "x.y", "z"))
47 | expect_named(
48 | cross_join(df1, df2, suffix = c("", "_y")),
49 | c("x", "y", "x_y", "z")
50 | )
51 | })
52 |
53 | test_that("cross join checks for duplicate names", {
54 | df1 <- tibble(a = 1, b = 2, a = 3, .name_repair = "minimal")
55 | df2 <- tibble(a = 2, c = 3)
56 |
57 | expect_snapshot(error = TRUE, {
58 | cross_join(df1, df2)
59 | })
60 | })
61 |
--------------------------------------------------------------------------------
/tests/testthat/test-locale.R:
--------------------------------------------------------------------------------
1 | test_that("`dplyr_legacy_locale()` is `FALSE` by default", {
2 | expect_false(dplyr_legacy_locale())
3 | })
4 |
5 | test_that("`dplyr_legacy_locale()` respects `dplyr.legacy_locale`", {
6 | local_options(dplyr.legacy_locale = TRUE)
7 | expect_true(dplyr_legacy_locale())
8 |
9 | local_options(dplyr.legacy_locale = 1)
10 | expect_snapshot(error = TRUE, {
11 | dplyr_legacy_locale()
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/tests/testthat/test-n-distinct.R:
--------------------------------------------------------------------------------
1 | test_that("n_distinct() counts empty inputs", {
2 | expect_equal(n_distinct(NULL), 0)
3 | expect_equal(n_distinct(data.frame()), 0)
4 | })
5 |
6 | test_that("n_distinct() counts unique values in simple vectors", {
7 | expect_equal(n_distinct(c(TRUE, FALSE, NA)), 3)
8 | expect_equal(n_distinct(c(1, 2, NA)), 3)
9 | expect_equal(n_distinct(c(1L, 2L, NA)), 3)
10 | expect_equal(n_distinct(c("x", "y", NA)), 3)
11 | })
12 |
13 | test_that("n_distinct() counts unique combinations", {
14 | expect_equal(n_distinct(c(1, 1, 1), c(2, 2, 2)), 1)
15 | expect_equal(n_distinct(c(1, 1, 2), c(1, 2, 2)), 3)
16 | })
17 |
18 | test_that("n_distinct() handles data frames", {
19 | expect_equal(n_distinct(data.frame(c(1, 1, 1), c(2, 2, 2))), 1)
20 | expect_equal(n_distinct(data.frame(c(1, 1, 2), c(1, 2, 2))), 3)
21 | })
22 |
23 | test_that("n_distinct() can drop missing values", {
24 | expect_equal(n_distinct(NA, na.rm = TRUE), 0)
25 | expect_equal(n_distinct(c(NA, 0), na.rm = TRUE), 1)
26 |
27 | expect_equal(n_distinct(c(NA, 0), c(0, NA), na.rm = TRUE), 0)
28 | expect_equal(n_distinct(c(NA, 0), c(0, 0), na.rm = TRUE), 1)
29 |
30 | # check tibbles unpacked correctly
31 | expect_equal(n_distinct(1, tibble(x = 2, y = NA), na.rm = TRUE), 0)
32 | })
33 |
34 | test_that("n_distinct() follows recycling rules", {
35 | expect_equal(n_distinct(double(), 1), 0)
36 | expect_equal(n_distinct(1:2, 1), 2)
37 | })
38 |
39 | test_that("n_distinct() generates useful errors", {
40 | expect_snapshot(error = TRUE, {
41 | n_distinct()
42 | n_distinct(x = 1:4)
43 | n_distinct(mean)
44 | })
45 | })
46 |
--------------------------------------------------------------------------------
/tests/testthat/test-near.R:
--------------------------------------------------------------------------------
1 | test_that("near accepts nearby fp values", {
2 | expect_true(near(sqrt(2)^2, 2))
3 | })
4 |
--------------------------------------------------------------------------------
/tests/testthat/test-nest-by.R:
--------------------------------------------------------------------------------
1 | test_that("returns expected type/data", {
2 | df <- data.frame(g = 1:2, x = 1:2, y = 1:2)
3 | out <- nest_by(df, g)
4 |
5 | expect_s3_class(out, "rowwise_df")
6 | expect_equal(group_vars(out), "g")
7 | expect_named(out, c("g", "data"))
8 | })
9 |
10 | test_that("can control key col", {
11 | df <- data.frame(g = 1:2, x = 1:2, y = 1:2)
12 | out <- nest_by(df, g, .key = "key")
13 | expect_named(out, c("g", "key"))
14 | })
15 |
16 | test_that("nest_by() inherits grouping", {
17 | df <- data.frame(g1 = 1:2, g2 = 1:2, x = 1:2, y = 1:2)
18 |
19 | expect_equal(
20 | df %>% group_by(g1) %>% nest_by() %>% group_vars(),
21 | "g1"
22 | )
23 |
24 | # And you can't have it both ways
25 | expect_error(df %>% group_by(g1) %>% nest_by("g2"), "re-group")
26 | })
27 |
28 | test_that("can control whether grouping data in list-col", {
29 | df <- data.frame(g = 1:2, x = 1:2, y = 1:2)
30 | out <- nest_by(df, g)
31 | expect_named(out$data[[1]], c("x", "y"))
32 |
33 | out <- nest_by(df, g, .keep = TRUE)
34 | expect_named(out$data[[1]], c("g", "x", "y"))
35 | })
36 |
--------------------------------------------------------------------------------
/tests/testthat/test-order-by.R:
--------------------------------------------------------------------------------
1 | test_that("order_by() gives useful error messages", {
2 | expect_snapshot({
3 | (expect_error(order_by(mtcars, 10)))
4 | (expect_error(order_by(mtcars, cyl)))
5 | })
6 | })
7 |
8 | test_that("`with_order()` works with data frame `order_by` (#6334)", {
9 | x <- 1:3
10 | order_by <- tibble(a = c(1, 1, 2), b = c(2, 1, 1))
11 |
12 | expect_identical(with_order(order_by, lag, x), c(2L, NA, 1L))
13 | })
14 |
15 | test_that("`with_order()` requires `order_by` and `x` to be the same size", {
16 | expect_snapshot(error = TRUE, {
17 | with_order(1:2, identity, 1:3)
18 | })
19 | })
20 |
21 | test_that("order_by() returns correct value", {
22 | expected <- int(15, 14, 12, 9, 5)
23 | expect_identical(order_by(5:1, cumsum(1:5)), expected)
24 |
25 | x <- 5:1
26 | y <- 1:5
27 | expect_identical(order_by(x, cumsum(y)), expected)
28 | })
29 |
30 | test_that("order_by() works in arbitrary envs (#2297)", {
31 | env <- child_env("base")
32 | expect_equal(
33 | with_env(env, dplyr::order_by(5:1, cumsum(1:5))),
34 | rev(cumsum(rev(1:5)))
35 | )
36 | expect_equal(
37 | order_by(5:1, cumsum(1:5)),
38 | rev(cumsum(rev(1:5)))
39 | )
40 | })
41 |
42 | test_that("order_by() give meaningful errors", {
43 | expect_snapshot({
44 | (expect_error(order_by(NULL, 1L)))
45 | })
46 | })
47 |
--------------------------------------------------------------------------------
/tests/testthat/test-pull.R:
--------------------------------------------------------------------------------
1 | test_that("default extracts last var from data frame", {
2 | df <- tibble(x = 1:10, y = 1:10)
3 | expect_equal(pull(df), 1:10)
4 | })
5 |
6 | test_that("can extract by name, or positive/negative position", {
7 | x <- 1:10
8 | df <- tibble(x = x, y = runif(10))
9 |
10 | expect_equal(pull(df, x), x)
11 | expect_equal(pull(df, 1L), x)
12 | expect_equal(pull(df, 1), x)
13 | expect_equal(pull(df, -2), x)
14 | expect_equal(pull(df, -2L), x)
15 | })
16 |
17 | test_that("can extract named vectors", {
18 | x <- 1:10
19 | y <- letters[x]
20 | df <- tibble(x = x, y = y)
21 | xn <- set_names(x, y)
22 |
23 | expect_equal(pull(df, x), x)
24 | expect_equal(pull(df, x, y), xn)
25 | expect_equal(pull(df, 1, 2), xn)
26 | expect_equal(names(pull(df, x, y)), y)
27 | })
28 |
--------------------------------------------------------------------------------
/tests/testthat/test-select-helpers.R:
--------------------------------------------------------------------------------
1 | test_that("group_cols() selects grouping variables", {
2 | df <- tibble(x = 1:3, y = 1:3)
3 | gf <- group_by(df, x)
4 |
5 | expect_equal(df %>% select(group_cols()), df[integer()])
6 | expect_message(
7 | expect_equal(gf %>% select(group_cols()), gf["x"]),
8 | NA
9 | )
10 | })
11 |
12 | test_that("group_cols(vars) is deprecated", {
13 | expect_warning(out <- group_cols("a"), "deprecated")
14 | expect_equal(out, integer())
15 | })
16 |
17 | test_that("group_cols() finds groups in scoped helpers", {
18 | gf <- group_by(tibble(x = 1, y = 2), x)
19 | out <- select_at(gf, vars(group_cols()))
20 | expect_named(out, "x")
21 | })
22 |
--------------------------------------------------------------------------------
/tests/testthat/test-src-dbi.R:
--------------------------------------------------------------------------------
1 | test_that("can work directly with DBI connection", {
2 | skip_if_not_installed("RSQLite")
3 | skip_if_not_installed("dbplyr")
4 |
5 | con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
6 | on.exit(DBI::dbDisconnect(con))
7 |
8 | df <- tibble(x = 1:10, y = letters[1:10])
9 | df1 <- copy_to(con, df)
10 | df2 <- tbl(con, "df")
11 |
12 | expect_equal(collect(df1), df, ignore_attr = TRUE)
13 | expect_equal(collect(df2), df, ignore_attr = TRUE)
14 | })
15 |
--------------------------------------------------------------------------------
/tests/testthat/test-tbl.R:
--------------------------------------------------------------------------------
1 | test_that("tbl_nongroup_vars() excludes group variables", {
2 | gdf <- group_by(mtcars, cyl)
3 | expect_identical(tbl_nongroup_vars(gdf), setdiff(tbl_vars(gdf), "cyl"))
4 | })
5 |
6 | test_that("tbl_vars() records groups", {
7 | gdf <- group_by(mtcars, cyl, am)
8 | expect_s3_class(tbl_vars(gdf), "dplyr_sel_vars")
9 | expect_true(is_sel_vars(tbl_vars(gdf)))
10 | expect_identical(tbl_vars(gdf) %@% groups, c("cyl", "am"))
11 | })
12 |
--------------------------------------------------------------------------------
/tests/testthat/test-top-n.R:
--------------------------------------------------------------------------------
1 | test_that("top_n returns n rows", {
2 | test_df <- data.frame(x = 1:10, y = 11:20)
3 | top_four <- test_df %>% top_n(4, y)
4 | expect_equal(dim(top_four), c(4, 2))
5 | })
6 |
7 | test_that("top_n() handles missing `wt`", {
8 | df <- data.frame(x = c(10, 4, 1, 6, 3, 1, 1))
9 | expect_message(
10 | regexp = "Selecting by x",
11 | expect_identical(top_n(df, 2)$x, c(10, 6))
12 | )
13 | })
14 |
15 | test_that("top_n() handles calls", {
16 | expect_identical(top_n(mtcars, 2, -disp), top_n(mtcars, -2, disp))
17 | })
18 |
19 | test_that("top_n() quotes n", {
20 | expect_snapshot(res1 <- top_n(mtcars, n() * .5))
21 | expect_snapshot(res2 <- top_n(mtcars, 16))
22 | expect_identical(res1, res2)
23 | })
24 |
25 | test_that("top_frac() is a shorthand for top_n(n()*)", {
26 | expect_identical(top_n(mtcars, n() * .5, disp), top_frac(mtcars, .5, disp))
27 |
28 | expect_snapshot(res1 <- top_n(mtcars, n() * .5))
29 | expect_snapshot(res2 <- top_frac(mtcars, .5))
30 | })
31 |
--------------------------------------------------------------------------------
/tests/testthat/utf-8.txt:
--------------------------------------------------------------------------------
1 | # UTF-8 tests that can't be run on Windows CRAN
2 | # R CMD check will try to parse the file anyway,
3 | # we use a different file extension to avoid this.
4 | df <- data.frame(中文1 = 1:10, 中文2 = 1:10, eng = 1:10)
5 | df2 <- df %>% mutate(中文1 = 中文1 + 1)
6 | gdf2 <- df %>% group_by(eng) %>% mutate(中文1 = 中文1 + 1)
7 |
8 | expect_equal(lobstr::obj_addrs(names(df)), lobstr::obj_addrs(names(df2)))
9 | expect_equal(lobstr::obj_addrs(names(df)), lobstr::obj_addrs(names(gdf2)))
10 |
11 | df3 <- filter(df2, eng > 5)
12 | gdf3 <- filter(gdf2, eng > 5)
13 | expect_equal(lobstr::obj_addrs(names(df)), lobstr::obj_addrs(names(df3)))
14 | expect_equal(lobstr::obj_addrs(names(df)), lobstr::obj_addrs(names(gdf3)))
15 |
16 | df4 <- filter(df2, 中文1 > 5)
17 | gdf4 <- filter(gdf2, 中文1 > 5)
18 | expect_equal(lobstr::obj_addrs(names(df)), lobstr::obj_addrs(names(df4)))
19 | expect_equal(lobstr::obj_addrs(names(df)), lobstr::obj_addrs(names(gdf4)))
20 |
--------------------------------------------------------------------------------
/vignettes/.gitignore:
--------------------------------------------------------------------------------
1 | figure
2 | *.html
3 | *.md
4 | rsconnect
5 | *.R
6 |
--------------------------------------------------------------------------------