Really wrong code or qplot was not updated to the latest 'rlang' version?

46 views
Skip to first unread message

Rodrigo Botafogo

unread,
Jan 24, 2019, 10:54:40 AM1/24/19
to ggplot2
Hello....

I have the following code:

    library('ggplot2')
    library('ISLR')
    library('MASS')
 
    err_plot = function(lstat, medv) {
         qplot(!!lstat, !!medv)
    }
 
    err_plot(Boston$lstat, Boston$medv)

And this issues the following error:

Error: `expr` must quote a symbol, scalar, or call Call `rlang::last_error()` to see a backtrace


I thought this should be valid code in 'tidyverse' and the expr should 'inline ...' the given vectors.  Is the code illegal or is it that qplot was not updated?

Thanks!

Marios Barlas

unread,
Jan 24, 2019, 12:55:34 PM1/24/19
to ggplot2, Rodrigo Botafogo
What's the double.!! In your qplot call? Never seen it before


From: ggp...@googlegroups.com <ggp...@googlegroups.com> on behalf of Rodrigo Botafogo <rodrigo.a...@gmail.com>
Sent: Thursday, January 24, 2019 4:51:40 PM
To: ggplot2
Subject: Really wrong code or qplot was not updated to the latest 'rlang' version?
 
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brandon Hurr

unread,
Jan 24, 2019, 1:14:01 PM1/24/19
to Rodrigo Botafogo, ggplot2
I think the error is saying that you’ve missed a step. 

!! (Bang bang) is expecting a symbol so you need to make your input variables symbols with  rlang::sym(). 

err_plot = function(lstat, medv) {
lstat <-  sym(lstat)
medv <- sym(medv)

qplot(!!lstat, !!medv)
}

My favorite tutorial for tidy evaluation is here:

I know that Hadley has also updated his Advanced R book. 

HTH, 
B

--

Roman Luštrik

unread,
Jan 24, 2019, 1:21:26 PM1/24/19
to Brandon Hurr, Rodrigo Botafogo, ggplot2
I thought qplot went by the way of the dodo?

Cheers,
Roman
--
In God we trust, all others bring data.

Brandon Hurr

unread,
Jan 24, 2019, 1:27:42 PM1/24/19
to Roman Luštrik, Rodrigo Botafogo, ggplot2

I remembered something like this too, but I don't see anything in the recent release notes to indicate that this is the case. 

Also, it does still work. 

library(ggplot2)
qplot(mtcars$hp, mtcars$disp)
Screen Shot 2019-01-24 at 3.26.32 PM.png

B

Reply all
Reply to author
Forward
0 new messages