- Part A
- R-packages – an introduction (10 minutes)
- Structure and contents of R-packages (30 minutes)
- From scripts to functions (20 minutes)
- Part B
- Building a template package the prospective way (10 minutes)
- Maintaining a package (20 minutes)
January 18, 2017
Alternatively use devtools::create("path/to/package/pkgname")
Alternatively (DON'T) use package.skeleton()
. It will create an overloaded package template that needs more modification.
The R environment is completely empty
Close and delete the template function and its documentation straight away.
Inspect the NAMESPACE and DESCRIPTION file.
The NAMESPACE contains only: exportPattern("^[[:alpha:]]+")
, i.e., every function is exported!
The DESCRIPTION file contains autogenerated content. Modify it so that it fits your needs.
It is now time to add some functions to the package.
PACKAGE_VERSION_tar.gz
-file in your R directoryCheck
stops with an error? See where the error happend:
Software lives, it evolves, it ages and it gets kicked by changed hardware.
Thus, software needs to be maintained and updated. But by more than just fixing a bug and raising the version number.
Maintenance should be handled as open, transparent and coherent as possible.
Git is a perfect versioning tool, and R and RStudio perfectly align with it.
SmartGit is a local client software for Git (alternative to Git via console)
It is very likely you use only a tiny fraction of the functionality
Git(Hub) makes spotting well-hidden coding accidents deliberately easy
Further information about Git: well, I had not found time for everything :)
git config --global user.name "YOUR FULL NAME" git config --global user.email "YOUR EMAIL ADDRESS"
git config --global --list
Confirm and let RStudio restart itself
Click on the Git tab in the upper right window
That was it! All changes made will now be tracked.
git checkout <SHA> <filename>
)SmartGit is a powerful GUI for Git. Whatever you cannot do in RStudio, you can do it in SmartGit
We installed SmartGit mainly for getting access to additional options
Instead of using RStudio for tracking changes, we can use SmartGit as well
How to turn a script into a function
Using Git via RStudio to maintain a package
It doesn’t matter if your first version isn’t perfect as long as the next version is better. (H. Wickham)