Chapter 4. Case Study: Creating a Package
Before describing more systematically the components that RStudio provides for development work in R (most importantly the source-code editor), we will pick up where we left off on our case study of analyzing the group behavior and individual movements of a colony of naked mole rats. Here, our goal is to illustrate one way to do package development with RStudio.
Imagine after a short time using RStudio for interactive use, that we
are pretty happy using the command line for short commands, but have learned
to really enjoy writing scripts in the Code editor. Even 2- or 3-line commands are much
easier to debug when done in the editor. The directness of typing at the
command line isn’t lost, as our fingers are now trained to hit Ctrl+Enter to
send the current line or selection to the R interpreter—or even
Ctrl+Shift+Enter to send the entire buffer (Command, not Ctrl, for Mac
users). We never need to leave the keyboard unless we choose to.
Along the way, we have been able to create a large script file that we now want to share with a colleague.
How do we do this? There are many ways. We could just send along the entire script, or with just a bit more extra work, we could share our work through a version control system. In some cases, this approach might be the best thing to do, as then our colleague can do exactly what we have been doing. However, there are many situations where this isn’t so great. For example, perhaps this colleague doesn’t know ...