Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Packages - What is the file 'zzz.R' used for?

Tags:

package

r

I'm planning to condense some of my code into a package, and was looking at the source of a few published packages on CRAN as a guide. I notice many packages include the file R\zzz.R, so I presume there must be some convention surrounding this.

However, I cannot find any mention of zzz.R in the official Writing R Extensions guide. What is this file for, and do I need to include one in my package? Why is it named the way it is - why not zzzz.R?

like image 286
mchen Avatar asked Jan 30 '14 05:01

mchen


2 Answers

It's a file where one usually puts actions on load of the package. It is tradition/convention that it's called zzz.R and could be called anything.R

You only need to include this if you want you package to do something out of the ordinary when it loads. Keep looking at what people put in there and you'll begin to get a sense of what they're used for.

like image 170
Tyler Rinker Avatar answered Oct 21 '22 03:10

Tyler Rinker


This zzz.R file was also mentioned by Hadley Wickham in his book "R packages", at the bottom of "When you do need side-effects" section.

https://r-pkgs.org/Code.html#when-you-do-need-side-effects

If you use .onLoad(), consider using .onUnload() to clean up any side effects. By convention, .onLoad() and friends are usually saved in a file called R/zzz.R. (Note that .First.lib() and .Last.lib() are old versions of .onLoad() and .onUnload() and should no longer be used.)

like image 20
SHUAICHENG WANG Avatar answered Oct 21 '22 05:10

SHUAICHENG WANG