Step 8: The sample package

To show you how this is done we have to create a sample package.  Before you jump to do that create   a new directory from your working directory. For this excercise I’ve created a new directory called “TestPackage”.  Start your R session and change your working directory to be the new directory you have created.

 getwd()
[1] "C:/Users/steve/Documents/TestPackage"

So, now that I’m in  my TestPackage directory, I’m going to create a test package. To do this we are going to use a tool called package.skeleton. At your prompt, enter ?package.skeleton(). read this help carefully as it explains what you will have to do in the future when you make your own packages.  Since I’m using RStudio I merely cut and past the example code into my console

require(stats)
## two functions and two "data sets" :
f <- function(x,y) x+y
g <- function(x,y) x-y
d <- data.frame(a=1, b=2)
e <- rnorm(1000)

package.skeleton(list=c("f","g","d","e"), name="mypkg")

And then I execute that code

And you should get the following message in your console

Creating directories ...
Creating DESCRIPTION ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './mypkg/Read-and-delete-me'.

And you can check that the files were created. Here is what my system looks like now.

So following the instructions lets look at the Read-and-delete-me file. I just used RStudio to do that. And I get a look at the file

* Edit the help file skeletons in 'man', possibly combining help files for
  multiple functions.
* Put any C/C++/Fortran code in 'src'.
* If you have compiled code, add a .First.lib() function in 'R' to load the
  shared object.
* Run R CMD build to build the package tarball.
* Run R CMD check to check the package tarball.

Read "Writing R Extensions" for more information.

The instructions are pretty clear. I have to edit the manual files in order to build properly. On to step 9

  1. David Farrar
    December 19, 2012 at 9:16 PM | #1

    Instructions above generated by package.skeleton() may not be entirely clear to all users who are not programmers, particularly that business about tarballs, not actually something the user necesarily wants. How about, “Taking things one step at a time we will next edit the manual files as instructed. The other instuctions will be covered at later steps.”

  1. June 9, 2011 at 12:20 AM | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: