Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor error message when "missing" format objects #114

Closed
MichaelChirico opened this issue Oct 30, 2018 · 2 comments

Comments

@MichaelChirico
Copy link

commented Oct 30, 2018

I made the mistake not to include some of the named elements & was met with a very strange error it took me a while to figure out:

Error in as.character(.transformer(expr, env)) :
cannot coerce type 'closure' to vector of type 'character'

This is because my input was actually a named function (and even though closure should have been a dead giveaway on this I spent 10 minutes + debugging):

glue::glue_data(list(x = 1), '{x} cannot be bigger than {stop}')

I'm not sure any easy way to fix this/give a more helpful message, but if so it could save time debugging.

@jimhester

This comment has been minimized.

Copy link
Member

commented Jan 4, 2019

We will look into this during the Tidy dev day at RStudio::conf.

I think the easiest way to fix it would be to have glue use a small wrapper around as.character() which provides a more informative error message than the default when the coercion fails.

glue/R/glue.R

Line 105 in fcdfa61

f <- function(expr) as.character(.transformer(expr, env))

ref. tidyverse error messages

@ijlyttle

This comment has been minimized.

Copy link
Contributor

commented Jan 19, 2019

claiming! first stop reprex!

jimhester added a commit that referenced this issue Jan 26, 2019

More informative error message if function is interpolated (#123)
We now test if the string is a function and throw an error if so, with the caveat that crayon functions can be coerced to characters with `as.character()` (and are in the vignette) so we only error if that coercion fails.

Fixes #114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.