-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Shapes provided via strings instead of integers #2338
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
Conversation
Could you please add a couple of unit tests for We also need to consider where this behaviour should be documented. Somewhere in |
R/scale-manual.r
Outdated
@@ -56,6 +56,12 @@ scale_size_manual <- function(..., values) { | |||
#' @rdname scale_manual | |||
#' @export | |||
scale_shape_manual <- function(..., values) { | |||
if (is.character(values) && nchar(values[1]) > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to incorporate the existing behaviour for single letters in to translate_shape_string()
. An easy way do that would be to combine pch_table
with setNames(letters, letter)
R/geom-point.r
Outdated
"18" = "diamond", | ||
"19" = "circle", | ||
"20" = "bullet", | ||
"21" = "circle filled ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing space
R/geom-point.r
Outdated
@@ -98,6 +98,14 @@ geom_point <- function(mapping = NULL, data = NULL, | |||
na.rm = FALSE, | |||
show.legend = NA, | |||
inherit.aes = TRUE) { | |||
dots <- list(...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right place to do translation - it would be better to do so during drawing.
I'll get on those and update the pull request this weekend. I think documentation in |
Are you interesting in finishing this off? Sorry for dropping the ball on you, but there are a few little style tweaks needed. No problem if you don't have time in the next week, just let me know and I'll do it myself (but I wanted you to have the opportunity to finally take this over the finish line if you wanted) |
Sure, let me know! |
invalid_strings <- is.na(shape_match) | ||
nonunique_strings <- shape_match == 0 | ||
|
||
if (any(invalid_strings)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please follow the standard tidyverse style here? (Main problem is that )
should go on own line; you can use styler package to do automatically)
R/geom-point.r
Outdated
bad_string <- unique(shape_string[invalid_strings]) | ||
collapsed_names <- paste0(bad_string, collapse = "', '") | ||
stop( | ||
"Invalid shape name: '", collapsed_names, "'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind having a read of http://style.tidyverse.org/error-messages.html and seeing if you can rewrite these errors to more closely follow the guidelines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the ambiguous shape names, I've just put in the number of matches that the string would give; I'm not sure, but it might be nicer to give something like the following?
'tri' matches: triangle, triangle open, and 3 others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's probably a bit too much effort for this case
@@ -0,0 +1,81 @@ | |||
context("translate_shape_string") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests should go in tests/testthat/test-geom-point.R
context("translate_shape_string") | ||
|
||
test_that("strings translate to their corresponding integers", { | ||
shape_strings <- c( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to systematically test ever possible value - the main thing you want to achieve in this test is to make sure everything is plumbed together correctly.
}) | ||
|
||
test_that("non-unique substrings of shape names raise an error", { | ||
shape_strings <- c( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly you only need to test a single string here, and in the next error (and you could probably combine the two tests)
Also, would it be best to document this in the Aesthetic Specifications vignette? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention in the aesthetic specification vignette would be great!
NEWS.md
Outdated
@@ -177,6 +180,7 @@ up correct aspect ratio, and draws a graticule. | |||
use matrix-columns. These are rarely used but are produced by `scale()`; | |||
to continue use `scale()` you'll need to wrap it with `as.numeric()`, | |||
e.g. `as.numeric(scale(x))`. | |||
>>>>>>> upstream/master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed this
tests/testthat/test-geom-point.R
Outdated
@@ -0,0 +1,32 @@ | |||
context("translate_shape_string") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this should now become geom-point
tests/testthat/test-geom-point.R
Outdated
) | ||
|
||
expect_equal(translate_shape_string(shape_strings[1]), 0) | ||
expect_equal(translate_shape_string(shape_strings), 0:2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not immediately clear to me what the intent of these tests are — I think it's to check that translate_shape_string()
is vectorised? If so, I think you should create a new test, and I think you should only need one expectation.
Looks good! Can you please take a look at the CI failures? You might just need to merge/rebase to get fixes from the master branch. |
All passing now (the perils of using newer base R functions!) |
Thanks for all your hard work on this! |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Implementation of #2075