-
Notifications
You must be signed in to change notification settings - Fork 116
label_parse with an Empty String Shifts Labels to Incorrect Locations #159
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
Comments
The issue appears to be that here: Line 116 in 8d23845
The parse function when provided an empty string as part of a vector of inputs returns a shorter vector of expressions: > parse(text=c("", "A", "B[C]"))
expression(A, B[C])
> length(parse(text=c("", "A", "B[C]")))
[1] 2 While I think that this is a difficulty in base R (reported as such: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17471), I think that the behavior is unlikely to change, and it is probably viewed as a feature. Something like the following may work: lab_char <- as.character(lab)
lab <- expression()
lab[!(lab_char %in% "")] <- parse(text=lab_char[!(lab_char %in% "")]) |
Yes, this is definitely part of > Txt <- c("pi", "# A comment; the next is just empty", " ", "1+2")
> parse(text=Txt)
expression(pi, 1+2)
> and as you say yourself (in the bugzilla report) this is well documented. I think that the "mistake" is in your design that Both R's |
I’m confused then: If the user should directly give expression (as is the case for many other plotting functions), then they should never need to be parsed, and the If I would be happy to submit that as a PR. |
I think Martin is referncing the approach used in ggplot2 (and hence, ggraph) more than how you try to use it. I think a reason for the current approach is that ggplot2 works with data from dataframes and a column of calls are pretty rare. This in turn led to the current approach of specifying if a character column should be interpreted as an expression. In any way the original bug is valid in ggraph and will be fixed |
When a label has an empty string in it, the result appears to be shifted off by one. Note the bottom right and the bottom left in the second image below.
Created on 2018-09-14 by the reprex package (v0.2.0).
The text was updated successfully, but these errors were encountered: