Tobias Byland
2015-Nov-21 23:33 UTC
[R] summarize_ (NSE) in combination with quantile not working
Hi everyone, I am stumbling over the following issue when using the NSE (non-standard evaluation) of the summarise function in dpylr (as described here: https://cran.r-project.org/web/packages/dplyr/vignettes/nse.html): mtcars %>% summarise(min(mpg)) # summarize and min mtcars %>% summarise_("min(mpg)") # summarize_ and min mtcars %>% summarise(quantile(mpg, 0.1)) # summarize and quantile mtcars %>% summarise_("quantile(mpg, 0.1)") # summarize_ and quantile -> ERROR The last (and only the last) call results in the following error: Error: could not find function "quantile" It seems to me, that the combination of summarise_ and quantile() somehow doesn't work. Does anyone have an idea what the issue here is? Thanks a lot! Regards Tobi [[alternative HTML version deleted]]
Jeff Newmiller
2015-Nov-22 02:15 UTC
[R] summarize_ (NSE) in combination with quantile not working
Please post using plain text. The following works. mutate %>% summarise_( ~quantile( mpg, 0.1 ) ) Read the vignette on nse that comes with dplyr, or Google the error message. On November 21, 2015 3:33:16 PM PST, Tobias Byland <tobias at byland.info> wrote:>Hi everyone, > >I am stumbling over the following issue when using the NSE >(non-standard >evaluation) of the summarise function in dpylr (as described here: >https://cran.r-project.org/web/packages/dplyr/vignettes/nse.html): > >mtcars %>% summarise(min(mpg)) # summarize and min >mtcars %>% summarise_("min(mpg)") # summarize_ and min >mtcars %>% summarise(quantile(mpg, 0.1)) # summarize and quantile >mtcars %>% summarise_("quantile(mpg, 0.1)") # summarize_ and >quantile -> ERROR > >The last (and only the last) call results in the following error: > >Error: could not find function "quantile" > > >It seems to me, that the combination of summarise_ and quantile() >somehow doesn't work. > >Does anyone have an idea what the issue here is? > >Thanks a lot! > >Regards >Tobi > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- Sent from my Android device with K-9 Mail. Please excuse my brevity. [[alternative HTML version deleted]]
David Winsemius
2015-Nov-22 03:08 UTC
[R] summarize_ (NSE) in combination with quantile not working
> On Nov 21, 2015, at 3:33 PM, Tobias Byland <tobias at byland.info> wrote: > > Hi everyone, > > I am stumbling over the following issue when using the NSE (non-standard > evaluation) of the summarise function in dpylr (as described here: > https://cran.r-project.org/web/packages/dplyr/vignettes/nse.html): > > mtcars %>% summarise(min(mpg)) # summarize and min > mtcars %>% summarise_("min(mpg)") # summarize_ and min > mtcars %>% summarise(quantile(mpg, 0.1)) # summarize and quantile > mtcars %>% summarise_("quantile(mpg, 0.1)") # summarize_ and > quantile -> ERROR > > The last (and only the last) call results in the following error: > > Error: could not find function ?quantile"You should have noticed that the error had double-quotes around the function name. That?s very un-Rlich. You should have been satisfied with the third variation.> > > It seems to me, that the combination of summarise_ and quantile() > somehow doesn't work. >If thine code offends thee, pluck it out. ? David.> Does anyone have an idea what the issue here is? > > Thanks a lot! > > Regards > Tobi > > [[alternative HTML version deleted]]And while you are at it can you pluck out the HTML???????> > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius Alameda, CA, USA
Sébastien Durier
2015-Nov-23 20:59 UTC
[R] summarize_ (NSE) in combination with quantile not working
Hello, A more explicit response can be found in : https://cran.r-project.org/web/packages/lazyeval/vignettes/lazyeval.html where it is explained that : "quoted called and strings don?t have environments associated with them, so as.lazy() defaults to using baseenv(). This will work if the expression is self-contained (i.e. doesn?t contain any references to variables in the local environment), and will otherwise fail quickly and robustly." So summarise_ seems to work with "min" because this function is in the base package, but not with "quantile" which is in the stats package. A solution using strings could be : summarise_(mtcars, "stats::quantile(mpg, 0.1)") SD On 22/11/2015 03:15, Jeff Newmiller wrote:> Please post using plain text. The following works. > > mutate %>% summarise_( ~quantile( mpg, 0.1 ) ) > > Read the vignette on nse that comes with dplyr, or Google the error message. > > On November 21, 2015 3:33:16 PM PST, Tobias Byland <tobias at byland.info> wrote: >> Hi everyone, >> >> I am stumbling over the following issue when using the NSE >> (non-standard >> evaluation) of the summarise function in dpylr (as described here: >> https://cran.r-project.org/web/packages/dplyr/vignettes/nse.html): >> >> mtcars %>% summarise(min(mpg)) # summarize and min >> mtcars %>% summarise_("min(mpg)") # summarize_ and min >> mtcars %>% summarise(quantile(mpg, 0.1)) # summarize and quantile >> mtcars %>% summarise_("quantile(mpg, 0.1)") # summarize_ and >> quantile -> ERROR >> >> The last (and only the last) call results in the following error: >> >> Error: could not find function "quantile" >> >> >> It seems to me, that the combination of summarise_ and quantile() >> somehow doesn't work. >> >> Does anyone have an idea what the issue here is? >> >> Thanks a lot! >> >> Regards >> Tobi >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >