How to pass an unqoted column name to another method?

27 views
Skip to first unread message

holger brandl

unread,
Dec 8, 2017, 11:06:50 AM12/8/17
to manipulatr
Hi,

I'd like to pass on a bare column name to another method:

plot_hist = function(df, column){
quoCol= enquo(column)

hist(pull(df, !!quoCol))
}

plot_hist(iris, Petal.Width) ## works as expected



# here another method that internally should call plot_hist:
do_stuff = function (df, column){
plot_hist(df, column)
# ... more stuff
}

do_stuff(iris, Petal.Width) ## does not work but fails with

Error in overscope_eval_next(overscope, expr) : 

  object 'Petal.Width' not found

plot_hist should stay as it is, but do_stuff needs to be changed somehow, I guess.

What am I doing wrong here? 

Thanks,
best regards,
Holger

Hadley Wickham

unread,
Dec 8, 2017, 1:55:41 PM12/8/17
to holger brandl, manipulatr
do_stuff() needs to enquo() and then unquote when calling plot_hist(). (Quasiquotation is sort of infectious)

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+unsubscribe@googlegroups.com.
To post to this group, send email to manip...@googlegroups.com.
Visit this group at https://groups.google.com/group/manipulatr.
For more options, visit https://groups.google.com/d/optout.


--
http://hadley.nz

Holger Brandl

unread,
Dec 9, 2017, 3:33:26 PM12/9/17
to Hadley Wickham, manipulatr
Thanks Hadley, 

it works perfectly now.

Best,
Holger

Hadley Wickham <h.wi...@gmail.com> schrieb am Fr., 8. Dez. 2017 um 19:55 Uhr:
do_stuff() needs to enquo() and then unquote when calling plot_hist(). (Quasiquotation is sort of infectious)

Hadley


On Saturday, December 9, 2017, holger brandl <holger...@gmail.com> wrote:
Hi,

I'd like to pass on a bare column name to another method:

plot_hist = function(df, column){
quoCol= enquo(column)

hist(pull(df, !!quoCol))
}

plot_hist(iris, Petal.Width) ## works as expected



# here another method that internally should call plot_hist:
do_stuff = function (df, column){
plot_hist(df, column)
# ... more stuff
}

do_stuff(iris, Petal.Width) ## does not work but fails with

Error in overscope_eval_next(overscope, expr) : 

  object 'Petal.Width' not found

plot_hist should stay as it is, but do_stuff needs to be changed somehow, I guess.

What am I doing wrong here? 

Thanks,
best regards,
Holger

--
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.
Reply all
Reply to author
Forward
0 new messages