dreamRs / esquisse

RStudio add-in to make plots interactively with ggplot2
https://dreamrs.github.io/esquisse
Other
1.76k stars 228 forks source link

add data(name, package) to code export #150

Closed GregorDeCillia closed 3 years ago

GregorDeCillia commented 3 years ago

Hello. Let me first say thank you for this fantastic package. I'll use this package soon for a datviz course and would like to suggest a small, but significant improvement.

When datasets are loaded from packages, the R code export does not contain any lines to load the dataset in the environment. It would be very useful for beginners if you could add a line like data(name, package) or package::name here, so the generated code can be run without any setup operations. Example

data("tips", package = "reshape2")
ggplot(tips) + aes(total_bill, tip, colour = smoker, size = size) + geom_point() 

or

ggplot(reshape2::tips) + aes(total_bill, tip, colour = smoker, size = size) + geom_point() 
pvictor commented 3 years ago

Hello, Thank you 😄

Good idea, I've implemented option 2 (easier). You have to re-install esquisse and datamods from GitHub :

remotes::install_github("dreamRs/datamods")
remotes::install_github("dreamRs/esquisse")

I'll plan a release on CRAN next week.

Best,

Victor

GregorDeCillia commented 3 years ago

Thank you very much! After the update of datamods and esquisse, the data is imported with the :: syntax. However, I am now running into issues with the dplyr filters. In the plot below, all levels of reshape2::tips$day are displayed even tough the code export uses

`reshape2::tips` %>% filter(day %in% c("Sun", "Sat"))

I assume this has something to do with the implementation of this feature since datasets from the global environment are filtered correctly. Another thing I noticed is that there are backticks (`) around the dataset name.

esquisser

pvictor commented 3 years ago

Ah yes thanks, should be solved if you re-install both packages (esquisse and datamods).

This was caused by the fact that even if the data is not specified in the displayed code, the executed code contains a call to ggplot(reshape2::tips) and this object can't be overwritten by the new data filtered.

Victor

GregorDeCillia commented 3 years ago

Works like a charm now. Thanks a lot for your efforts!