Repository navigation
Shapes provided via strings instead of integers - #2338
Conversation
|
Could you please add a couple of unit tests for We also need to consider where this behaviour should be documented. Somewhere in |
| #' @rdname scale_manual | ||
| #' @export | ||
| scale_shape_manual <- function(..., values) { | ||
| if (is.character(values) && nchar(values[1]) > 1) { |
There was a problem hiding this comment.
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)
| "18" = "diamond", | ||
| "19" = "circle", | ||
| "20" = "bullet", | ||
| "21" = "circle filled ", |
| na.rm = FALSE, | ||
| show.legend = NA, | ||
| inherit.aes = TRUE) { | ||
| dots <- list(...) |
There was a problem hiding this comment.
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.
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)
| 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.
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.
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.
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.
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.
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.
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? |
hadley
left a comment
There was a problem hiding this comment.
Mention in the aesthetic specification vignette would be great!
| 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 |
| @@ -0,0 +1,32 @@ | |||
| context("translate_shape_string") | |||
There was a problem hiding this comment.
And this should now become geom-point
| ) | ||
|
|
||
| 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.
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