WinVector / rquery

Data Wrangling and Query Generating Operators for R. Distributed under choice of GPL-2 or GPL-3 license.
https://winvector.github.io/rquery/
Other
109 stars 15 forks source link

Documentation: Paramterized Queries with Multiple Columns #14

Closed prescient closed 4 years ago

prescient commented 4 years ago

Would it be possible to add a small tutorial on parameterizing rquery to perform transformations on multiple columns? Something similar to: https://cran.r-project.org/web/packages/rquery/vignettes/Parameterized_rquery.html but performing transformations on more than one column at a time. I thought I had figured this out at one point, but apparently forgot. If the documentation exists somewhere my apologies.

prescient commented 4 years ago

I'll close my particular issue as I figured out a minimal example using standard evaluation. NSE is still a bit of a mystery to me.

require(rqdatatable)
require(rquery)

cols <- c("mpg", "cyl", "hp")
denom <- c("wt")
col_labels <- paste0(cols, "_per_", denom)

mtcars %.>%
  extend_se(., 
         col_labels %:=% paste0(cols, "/", denom)) 
JohnMount commented 4 years ago

Actually you solved it the right way. NSE is a bad idea if taken too far. To my tastes standard evaluation is actually the right way to approach this sort of problem. Either way thanks for your note!

prescient commented 4 years ago

I appreciate your work on the package. Its good stuff!

JohnMount commented 4 years ago

Thanks, I am actually taking your advice and adding a small vignette.

prescient commented 4 years ago

Appreciate it. I've tried to perform similar paramterization with dplyr and could never figure it out (usually only one variable), and pure data.table is workable but controlling column names is a bit more confusing than it should be imo. This is the only package I've ever got working for this sort of stuff so I really appreciate it as it helps avoid boilerplate (currently staring at 200+ lines of boilerplate sql...).

JohnMount commented 4 years ago

Wow, it is great to hear from a happy user. I use rquery for my own work, and it has for me paid back its development time. Here is my current draft of a many columns vignette.

prescient commented 4 years ago

I just read the vignette and it is exactly what I was looking for. Thanks!