5

I need to display a disclaimer message when my package is loaded. After reading the posts

Library/package development - message when loading
Loading depending packages using .onLoad

I now have a zzz.R file that contains only

.onLoad <- function(libname, pkgname){
    packageStartupMessage('Regarding data obtained from www.retrosheet.org:\n
    The information used here was obtained free of charge from  
    and is copyrighted by Retrosheet. Interested parties may
    contact Retrosheet at "www.retrosheet.org"', domain = NULL, appendLF = TRUE)
}

I have two questions:

  1. Do I have to call .onLoad somewhere? Or does that happen automatically?

  2. I'm using the Collate field in the DESCRIPTION file. Does zzz.R need to be added to that list?


As a check, I run the following code. The package startup message appears when using install, but not when calling library, which I expect.

> library(devtools)
> install()
...
Reloading installed saber
Regarding data obtained from www.retrosheet.org:

The information used here was obtained free of charge from  
and is copyrighted by Retrosheet. Interested parties may
contact Retrosheet at "www.retrosheet.org"
...

> detach(package:saber)
> library(saber)

Attaching package: ‘saber’

The following objects are masked _by_ ‘.GlobalEnv’:

    getTeamData, relatedBatting
Community
  • 1
  • 1
Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
  • 1
    Must include. Doesn't matter where. Called automatically. – hadley Jul 08 '14 at 08:23
  • Thanks much. Do you have a hint as to why the `.onLoad` message prints when calling `devtools::install` but not `library` ? – Rich Scriven Jul 08 '14 at 08:29
  • 2
    it should print on library(mypackage), but only when the package was not loaded already – Remko Duursma Jul 08 '14 at 12:32
  • You should switch to using roxygen2. Note that in detach the unload parameter defaults to FALSE. Try using unload=TRUE and then reloading. – Dason Jul 08 '14 at 16:42
  • Every time I try to build I get Exit Status 1 and `pdflatex not found!` Do I have to install that as well? I have `roxygen2` installed. – Rich Scriven Jul 08 '14 at 20:55
  • @RichardScriven Yeah but you don't appear to use roxygen style comments in your code as far as I can tell from your github repo. – Dason Jul 08 '14 at 21:07
  • @Dason, right, I don't. But don't go by that repo, I don't update it often. many more files are strictly on my personal machine as I'm still learning how to push commits from RStudio. – Rich Scriven Jul 08 '14 at 21:10
  • @RichardScriven Sounds like you aren't using github properly ;) – Dason Jul 08 '14 at 21:10
  • As a word of warning - I've personally lost a month of work on a package because I used github like you currently are. I would suggest pushing much more regularly. What harm can it do? – Dason Jul 08 '14 at 21:12
  • Yeah, you're right. I really didn't know people were looking at it. It's a bit embarrassing in its current state. I did just send some new functions to `myUtils` though. – Rich Scriven Jul 08 '14 at 21:18
  • .onAttach is the hook searched when called via library(pckg)... https://stat.ethz.ch/R-manual/R-devel/library/base/html/ns-hooks.html – eflores89 Jul 14 '15 at 14:40

0 Answers0