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

Better handling of i and j in dt() #806

Merged
merged 4 commits into from
Mar 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Imports:
rlang (>= 1.1.0),
tidyselect (>= 1.2.0),
vctrs (>= 0.6.0)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
URL: https://markfairbanks.github.io/tidytable/, https://github.com/markfairbanks/tidytable
Expand Down
27 changes: 27 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ import(data.table, except = c(between, fread))
import(rlang, except = `:=`)
import(tidyselect)
import(vctrs)
importFrom(data.table,"%between%")
importFrom(data.table,"%chin%")
importFrom(data.table,"%like%")
importFrom(data.table,data.table)
importFrom(data.table,fwrite)
importFrom(data.table,getDTthreads)
importFrom(data.table,setDTthreads)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(glue,glue_data)
Expand All @@ -316,7 +323,27 @@ importFrom(magrittr,set_class)
importFrom(pillar,dim_desc)
importFrom(pillar,glimpse)
importFrom(pillar,tbl_sum)
importFrom(rlang,enexpr)
importFrom(rlang,enexprs)
importFrom(rlang,enquo)
importFrom(rlang,enquos)
importFrom(rlang,expr)
importFrom(rlang,exprs)
importFrom(rlang,quo)
importFrom(rlang,quos)
importFrom(rlang,sym)
importFrom(rlang,syms)
importFrom(stats,na.omit)
importFrom(tidyselect,all_of)
importFrom(tidyselect,any_of)
importFrom(tidyselect,contains)
importFrom(tidyselect,ends_with)
importFrom(tidyselect,everything)
importFrom(tidyselect,last_col)
importFrom(tidyselect,matches)
importFrom(tidyselect,num_range)
importFrom(tidyselect,starts_with)
importFrom(tidyselect,where)
importFrom(utils,head)
importFrom(utils,tail)
importFrom(utils,type.convert)
14 changes: 8 additions & 6 deletions R/dt.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#' Has experimental support for tidy evaluation for custom functions.
#'
#' @param .df A data.frame or data.table
#' @param ... Arguments passed to data.table call. See ``?data.table::`[.data.table` ``
#' @param i i position of a data.table call. See `?data.table::data.table`
#' @param j j position of a data.table call. See `?data.table::data.table`
#' @param ... Other arguments passed to data.table call. See `?data.table::data.table`
#'
#' @examples
#' df <- tidytable(
Expand All @@ -30,13 +32,13 @@
#' df %>%
#' add_one(x)
#' @export
dt <- function(.df, ...) {
dt <- function(.df, i, j, ...) {
UseMethod("dt")
}

#' @export
dt.tidytable <- function(.df, ...) {
dots <- enquos(..., .unquote_names = FALSE, .ignore_empty = "none")
dt.tidytable <- function(.df, i, j, ...) {
dots <- enquos(i, j, ..., .unquote_names = FALSE, .ignore_empty = "none")

if (has_length(dots, 0)) return(.df)

Expand Down Expand Up @@ -94,9 +96,9 @@ dt.tidytable <- function(.df, ...) {
}

#' @export
dt.data.frame <- function(.df, ...) {
dt.data.frame <- function(.df, i, j, ...) {
.df <- as_tidytable(.df)
dt(.df, ...)
dt(.df, {{ i }}, {{ j }}, ...)
}

# Checks if j is a single call to `:=` or let
Expand Down
4 changes: 1 addition & 3 deletions R/utils-general.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# dt starting with the j position
dt_j <- function(.df, j, ...) {
j <- enquo(j)
i <- new_quosure(expr(), get_env(j))
dt(.df, !!i, !!j, ...)
dt(.df, , {{ j }}, ...)
}

# Create a call to `[.data.table` (j position)
Expand Down
8 changes: 6 additions & 2 deletions man/dt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading