Make it easier to use tinyplot with pipes#347
Make it easier to use tinyplot with pipes#347mthulin wants to merge 1 commit intograntmcdermott:mainfrom
Conversation
|
Thanks for proposing this PR, it's a nice trick. However, I'm not sure whether we want to give away the possibility to have a dedicated Personally, rather than using the Personally, I find this easy enough to use. But maybe Grant @grantmcdermott and Vincent @vincentarelbundock feel differently. |
|
When I first saw this I got super excited and was about to post with great enthusiasm. But Achim's point about optionality is a very good one. I can also imagine other plots where maybe |
|
I won't have time to look at this until tonight. But perhaps we could implement a compromise solution that defaults to pair plots if a formula is not provided, otherwise adopts the trick proposed by @mthulin? We would probably also need to account for the fact that some data.frames (e.g., |
|
The naming-the-first-argument approach is nice! However, I guess that most users usually skip the x when working without pipes, so that they don't write: Personally, I'd prefer not to have to use special syntax to make the function work well with pipes. Similarly, I suspect that users coming from the tidyverse (who of course make up non-negligible proportion of R users) would consider it "a trick you have to do", whereas my solution is more in line with how users would expect things to work. That being said, I think that @grantmcdermott's idea of defaulting to a pairs plot unless a formula is provided is a great idea. I'd be happy to help with this if you choose to go down that route. |
|
Regarding the suggestion of handling the case with and without formula differently: I'm concerned that the arguments like |
|
Have you given this any more thought? Others may not agree of course, but for me, the one thing that's keeping me from migrating to tinyplot in my introductory R courses is that the syntax isn't as pipe-friendly as it could be; we use pipes a lot in my courses, and having to add |
|
TBC, I'm not the one who's going to make final call on this, but at this stage I think we should hold off on dedicating an important method for this little bit of syntactic convenience. We all have different teaching philosophies, but I would argue that a pipe-heavy introduction to R should absolutely include a module on argument passing. Otherwise students will try to do things like this: # breaks
mtcars |> lm(mpg ~ hp)
# works
mtcars |> lm(mpg ~ hp, data = _)So that could just be a nice opportunity to introduce this (very easy) programming concept. |
I completely agree on this. However, I don't think that the fact that legacy R functions weren't designed to work seamlessly with pipes is an argument for designing new functions that require special syntax to work with pipes. |
Sorry @mthulin, not enough to make a call. I think Vincent and Achim have raised enough good points above that we should be cautious about implementing without further testing. FWIW I hope to add a few basic methods to tinyplot in the next release (e.g., |
Currently, when
tinyplotis used with pipes,data = _must be passed to the function:This PR adds the method
tinyplot.data.frame, which lets users runtinyplotafter a pipe without having to use thedataargument:This should make it easier for pipe users to adopt
tinyplotinto their workflows.The function will throw an error if no formula is supplied. Running
yields
I added an example in the documentation, wrapped in \dontrun{} to avoid creating a dependency on R>=4.1.