How does dplyr decide when to combine multiple mutate statements?

65 views
Skip to first unread message

Jarod G.R. Meng

unread,
Jul 22, 2015, 12:54:16 AM7/22/15
to manipulatr
When I use dplyr on local data frames, I love the feature whereby mutate can refer to columns that I just created. However, when I use dplyr to translate the verbs into SQL, this feature can be problematic because databases usually don't support reference to newly-created columns. The workaround is to create layered subqueries, so I naturally tried to split my mutate statements and artificially create subqueries. Unfortunately dplyr seems to be automatically combining my multiple mutate statements when translating into SQL. Is there a way to ask dplyr *not* to combine multiple mutate statements (in other words, forcing dplyr to create individual subqueries)?

Thanks.

Genrong MENG

unread,
Jul 22, 2015, 1:34:13 PM7/22/15
to manipulatr
I boiled this down to the mutate_.tbl_sql function which only creates a subquery when window functions are used. Is it possible to add an argument to control the collapsing behavior so that users can choose when to create a subquery rather than just append the select statements?

On Tue, Jul 21, 2015 at 9:54 PM, Jarod G.R. Meng <genron...@gmail.com> wrote:
When I use dplyr on local data frames, I love the feature whereby mutate can refer to columns that I just created. However, when I use dplyr to translate the verbs into SQL, this feature can be problematic because databases usually don't support reference to newly-created columns. The workaround is to create layered subqueries, so I naturally tried to split my mutate statements and artificially create subqueries. Unfortunately dplyr seems to be automatically combining my multiple mutate statements when translating into SQL. Is there a way to ask dplyr *not* to combine multiple mutate statements (in other words, forcing dplyr to create individual subqueries)?

Thanks.

--
You received this message because you are subscribed to a topic in the Google Groups "manipulatr" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/manipulatr/OQyo7qSeBz4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to manipulatr+...@googlegroups.com.
To post to this group, send email to manip...@googlegroups.com.
Visit this group at http://groups.google.com/group/manipulatr.
For more options, visit https://groups.google.com/d/optout.

Hadley Wickham

unread,
Jul 24, 2015, 2:09:05 PM7/24/15
to Genrong MENG, manipulatr
I'd rather just fix the bug than adding a new syntax. In the mean
time you can use collapse() to force subquery creation.
Hadley
> You received this message because you are subscribed to the Google Groups
> "manipulatr" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to manipulatr+...@googlegroups.com.
> To post to this group, send email to manip...@googlegroups.com.
> Visit this group at http://groups.google.com/group/manipulatr.
> For more options, visit https://groups.google.com/d/optout.



--
http://had.co.nz/
Reply all
Reply to author
Forward
0 new messages