In my RStudio instance, executing the command data(package = 'ggplot2') renders its output to a tab in the 'Source Editor' pane -- is there a way of directing the output to the console? I ask because in require my students to post reproducible examples that include the output of their commands, and runningreprex() renders only the command itself.
The result of data(...) is of class 'packageIQR'. You can access the contents of the file that is being produced by looking at the 'results' element like so:
data(package = 'ggplot2')$results
Then, just wrap in as.data.frame to make it a nicer look, and customize from there:
Thanks Michael and Nir (@nirgrahamuk) -- It seems that objects of class packageIQR return results that can't be printed directly, which I don't yet understand. I had been hoping there might be an argument I could supply that would redirect where the dataset information would appear, but maybe that's not possible.
No one has asked you why you want to have your students use data(package=",,,") as part of an assignment. There are other R commands, like history()` that render output to a separate pane, but not ordinarily used in reproducible examples for assignments.
When they learn a new command, my students are required to write a post describing the behavior of the command that includes a reproducible example. I usually frame the task as an exercise in explaining something you learned in class to someone who was absent so they can both read through an example and reproduce it, and we happened to go over the data() command in class.
Here is a peek under the hood to what data() is doing when listing packages (i.e. use of the pager). I show where the content can be intercepted and printed in the 'normal' way.
Thanks, Nir! Where did the original function you modified come from? I've trying to locate source code that controls printing behavior, but with no success.
right, haha.
Yes, I used getAnywhere on data, to find that it was print.packageIRQ that was being used, and therefore I used geyAnywhere to investigate that in turn. glad I could help you along.