Skip to content

devOpifex/fassplyr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fassplyr

⚠️ This package is LLM-generated. The builder preprocessor it depends on is not.

A builder plugin that translates dplyr pipe chains to data.table syntax at build time.

Write idiomatic dplyr in your source files, get idiomatic data.table in your package: it uses builder to translate the code at build time.

🔴 This is a simple text repalcement (no AST parsing) so it's not perfect, consider this a proof of concept.

Usage

In your srcr/ source files, wrap dplyr pipe chains with #> fassplyr / #> endfassplyr markers:

library(data.table)

m <- mtcars

#> fassplyr
m |>
  dplyr::group_by(cyl) |>
  dplyr::summarise(mean_mpg = mean(mpg)) |>
  dplyr::arrange(dplyr::desc(mean_mpg))
#> endfassplyr

After running builder, the output in R/ becomes:

library(data.table)

m <- mtcars

data.table::as.data.table(m)[, .(mean_mpg = mean(mpg)), by = .(cyl)][order(-mean_mpg)]

Setup

Add the plugin to your builder.ini:

plugin: fassplyr::plugin

Or pass it to the CLI with the -plugin fassplyr::plugin.

Supported Verbs

dplyr data.table
dplyr::filter(cond1, cond2) [cond1 & cond2]
dplyr::select(col1, col2) [, .(col1, col2)]
dplyr::mutate(a = expr) [, :=(a = expr)]
dplyr::summarise(a = expr) [, .(a = expr)]
dplyr::arrange(x, dplyr::desc(y)) [order(x, -y)]
dplyr::group_by(g) by = .(g) on the next verb
dplyr::slice(1, 3) [c(1, 3)]
dplyr::distinct(col1, col2) unique(...[, .(col1, col2)])

dplyr::n() is replaced with .N. dplyr::desc(x) is replaced with -x inside arrange. Both n() and desc() also work without the dplyr:: prefix.

summarize (American spelling) is accepted as an alias for summarise.

Rules

  • Only the |> (native) pipe is supported
  • Verbs must use the dplyr:: prefix — bare verbs like filter() are not supported
  • Unrecognized verbs produce a warning and are passed through as comments

Not Supported

This is a proof of concept. The following are not handled:

  • %>% (magrittr pipe)
  • tidyselect helpers (starts_with(), everything(), where(), etc.)
  • Negative selection in select()
  • across() / c_across()
  • ungroup()
  • .data$ pronoun
  • Joins (left_join, inner_join, etc.)

About

dplyr to data.table

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages