Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vctrs instead of dplyr #902

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Imports:
Suggests:
covr,
crayon,
dplyr (>= 0.7.8),
knitr,
rmarkdown,
testthat (>= 3.0.0),
Expand Down
11 changes: 3 additions & 8 deletions R/flatten.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#' double vector, and `flatten_chr()` a character vector.
#'
#' `flatten_dfr()` and `flatten_dfc()` return data frames created by
#' row-binding and column-binding respectively. They require dplyr to
#' be installed.
#' row-binding and column-binding respectively.
#' @inheritParams map
#' @export
#' @examples
Expand Down Expand Up @@ -63,19 +62,15 @@ flatten_raw <- function(.x) {
#' @export
#' @rdname flatten
flatten_dfr <- function(.x, .id = NULL) {
check_installed("dplyr", "for `flatten_dfr()`.")

res <- .Call(flatten_impl, .x)
dplyr::bind_rows(res, .id = .id)
vctrs::vec_rbind(!!!res, .names_to = .id)
}

#' @export
#' @rdname flatten
flatten_dfc <- function(.x) {
check_installed("dplyr", "for `flatten_dfc()`.")

res <- .Call(flatten_impl, .x)
dplyr::bind_cols(res)
vctrs::vec_cbind(!!!res)
}

#' @export
Expand Down
13 changes: 4 additions & 9 deletions R/map.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#' atomic vector of the indicated type (or die trying).
#'
#' * `map_dfr()` and `map_dfc()` return a data frame created by
#' row-binding and column-binding respectively. They require dplyr
#' to be installed. `map_df()` is an alias for `map_dfr()`.
#' row-binding and column-binding respectively.
#'
#' * The returned values of `.f` must be of length one for each element
#' of `.x`. If `.f` uses an extractor function shortcut, `.default`
Expand Down Expand Up @@ -227,11 +226,9 @@ map_raw <- function(.x, .f, ...) {
#' Only applies to `_dfr` variant.
#' @export
map_dfr <- function(.x, .f, ..., .id = NULL) {
check_installed("dplyr", "for `map_dfr()`.")

.f <- as_mapper(.f, ...)
res <- map(.x, .f, ...)
dplyr::bind_rows(res, .id = .id)
vctrs::vec_rbind(!!!res, .names_to = .id)
}

#' @rdname map
Expand All @@ -242,11 +239,9 @@ map_df <- map_dfr
#' @rdname map
#' @export
map_dfc <- function(.x, .f, ...) {
check_installed("dplyr", "for `map_dfc()`.")

.f <- as_mapper(.f, ...)
res <- map(.x, .f, ...)
dplyr::bind_cols(res)
res <- unname(map(.x, .f, ...))
vctrs::vec_cbind(!!!res)
}

#' @rdname map
Expand Down
22 changes: 7 additions & 15 deletions R/map2-pmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' that a data frame is a very important special case, in which case `pmap()`
#' and `pwalk()` apply the function `.f` to each row. `map_dfr()`, `pmap_dfr()`
#' and `map2_dfc()`, `pmap_dfc()` return data frames created by row-binding
#' and column-binding respectively. They require dplyr to be installed.
#' and column-binding respectively.
#'
#' Note that arguments to be vectorised over come before `.f`,
#' and arguments that are supplied to every call come after `.f`.
Expand Down Expand Up @@ -136,21 +136,17 @@ map2_raw <- function(.x, .y, .f, ...) {
#' @rdname map2
#' @export
map2_dfr <- function(.x, .y, .f, ..., .id = NULL) {
check_installed("dplyr", "for `map2_dfr()`.")

.f <- as_mapper(.f, ...)
res <- map2(.x, .y, .f, ...)
dplyr::bind_rows(res, .id = .id)
vctrs::vec_rbind(!!!res, .names_to = .id)
}

#' @rdname map2
#' @export
map2_dfc <- function(.x, .y, .f, ...) {
check_installed("dplyr", "for `map2_dfc()`.")

.f <- as_mapper(.f, ...)
res <- map2(.x, .y, .f, ...)
dplyr::bind_cols(res)
res <- unname(map2(.x, .y, .f, ...))
vctrs::vec_cbind(!!!res)
}
#' @rdname map2
#' @export
Expand Down Expand Up @@ -228,21 +224,17 @@ pmap_raw <- function(.l, .f, ...) {
#' @rdname map2
#' @export
pmap_dfr <- function(.l, .f, ..., .id = NULL) {
check_installed("dplyr", "for `pmap_dfr()`.")

.f <- as_mapper(.f, ...)
res <- pmap(.l, .f, ...)
dplyr::bind_rows(res, .id = .id)
vctrs::vec_rbind(!!!res, .names_to = .id)
}

#' @rdname map2
#' @export
pmap_dfc <- function(.l, .f, ...) {
check_installed("dplyr", "for `pmap_dfc()`.")

.f <- as_mapper(.f, ...)
res <- pmap(.l, .f, ...)
dplyr::bind_cols(res)
res <- unname(pmap(.l, .f, ...))
vctrs::vec_cbind(!!!res)
}

#' @rdname map2
Expand Down
6 changes: 6 additions & 0 deletions revdep/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
checks/
logs/
data.sqlite
checks
library
checks.noindex
library.noindex
cloud.noindex
*.html
196 changes: 158 additions & 38 deletions revdep/README.md

Large diffs are not rendered by default.

Loading