Sunday, January 25, 2015

How to Create and Publish R package on CRAN : Step-by-Step Guide

  • R Studio (This tutorial is based on R studio 0.98.501)
  • Beginner level R programming skills
  • devtools package (to build and compile the code)
  • roxygen2 package (to create the documentation)
Lets break it down into 7 simple steps as following:
  1. Create R project
  2. Create function(s)
  3. Create  description file
  4. Create help file(s)
  5. Build, load and check the package
  6. Export package
  7. Submit on CRAN
Step 1

1.1  Open R Studio. Create a new project using "file > new project > new directory > empty project". Give directory name.

1.2  Install and load R packages "devtools" and "roxygen2".


1.3 Go to "Build > Configure buildtools"
Select "Package" from the dropdown menu

Check the option "Generate documentation with Roxygen". A popup window will open, make sure all six checkboxes are checked there.

1.4 Make sure, the build tab appears in top-right panel.

Step 2

Go to bottom right panel. Click on "files > new folder" and name the new folder as "R". This is the directory where we will save our code (functions).

In top left panel, click on "File > new File > R script". 
Write the function code in script file and save the file inside "R" directory.

Step 3

We need to create a description file where we an specify details like package name, title, description, author, maintainer, licence etc.

A simple way to create skeleton of description file is use bottom left panel (console) and give command "load_all()". It basically loads all the files. In our case it will create description file as it is not there and reload the package.

In bottom right panel you should be able to see the description file under "Files" tab.

Click on description file, it will get opened in top left panel. Lets put values in description file,

Save the file and use console to give command "load_all()". It will load the package with newly created description file. You should not see any errors or warning.

Step 4

Now next step is creating help file for the function we have written. We will add information about function in the same file containing the function code. Let's go to AddNumbers.R and add function description, input parameters of function, return value, references if any.

As you can see in screenshot above, we have added 11 lines before the actual function code.

The last parameter called "@exports" makes sure this function is publicly available to users of the package.

In some cases we might write a function for internal use of others function(s) in package. We can keep these internal functions private by not adding "@exports".

Step 5

Go to top right panel, "Build" tab and click on  "Build & Reload". You should see something like following,

In bottom left panel, you should be able to see the  package is re-loaded.

Now go to bottom right panel, "Packages" tab, you should see the package we have just created.

Click on it and explore if description file and help file looks fine.

Description file looks like,

Click on back arrow, go to AddNumbers help file. It should look like,

Now lets test if the function we have written actually works, in console.

Before we export the package, lets do a thorough check by "Build > Check" in top right panel.

There should NOT be any warnings or errors.

Step 6

Go to "Build > More > Build Source Package". It will create source package in 'tar.gz' format.
The output looks like,

Step 7

Make sure you are NOT violating any CRAN submission policies before you proceed.

Go to CRAN website,

It is a three step process.

Fill in the basic details, upload the package and hit "Upload package".

It will take you to step 2, where you can verify the details and click Submit.

All maintainers of the package listed in description file, will get an email for confirmation. After maintainers confirm it, CRAN moderators will review it. If the package adheres to CRAN policies it should get approved.

Congratulations! You are now officially a contributor to CRAN!


  1. We all need challenges in our life to keep motivated. I really had a great time scanning and reading your blog site and i was so amazed with your great artwork. I do hope you could inspire more readers. You can also visit my site for some interesting stuff.

  2. Wow. Awesome article. Please do more articles like this in the future. Very informational and knowledgeable. I will expect more from you in the future. For now i will just bookmark your page and surely I'm gonna come back later to read more. Thank you to the writer!


  3. Wiztech Automation Solutions is the Best Training institute in Chennai,started in the year 2006 and it extended its circle through providing the best Education as per the Global Quality Standards. Hence our Training Center in Chennai was Recognized by IAO and ISO for its inspiring Education Quality Standards. Wiztech Automation Solution, the PLC SCADA Training Academy in Chennai offers both PLC, SCADA, DCS, VFD, Drives, Control Panels, HMI, Pneumatics, Embedded systems, VLSI, IT, Web Designing, AutoCad Training courses in chennai with latest various brands. Wiztech Automation Solutions offers Real Time Training Courses with 100% Placement support in chennai.

    PLC Training in chennai
    SCADA Training in chennai
    PLC Training Institute in chennai
    Embedded System Training in chennai
    VLSI Training in chennai
    Automation Training in chennai
    Industrial Automation Training in chennai
    Process Automation Training in chennai
    DCS Training in chennai
    Inplant Training in chennai
    PLC Course in chennai
    Best PLC Training in chennai
    PLC Training in chennai
    Robotics Training in chennai
    Embedded Training in chennai
    IT Training in chennai
    Web designing Training in chennai
    AutoCad Training in chennai

  4. Welcome to Wiztech Automation - Embedded System Training in Chennai. We have knowledgeable Team for Embedded Courses handling and we also are after Job Placements offer provide once your Successful Completion of Course. We are Providing on Microcontrollers such as 8051, PIC, AVR, ARM7, ARM9, ARM11 and RTOS. Free Accommodation, Individual Focus, Best Lab facilities, 100% Practical Training and Job opportunities.

    Embedded System Training in chennai
    Embedded System Training Institute in chennai
    Embedded Training in chennai
    Embedded Course in chennai
    Embedded Systems Course in chennai
    Best Embedded System Training Institute in chennai
    Best Embedded System Training Institutes in chennai
    Embedded Training Institute in chennai
    Embedded System Course in chennai
    Best Embedded System Training in chennai
    VLSI Training in chennai

  5. Hi Admin,
    I went through your blog and it’s totally awesome. Keep on updating your site with such informative post. If possible please include rss feed for your blog. embedded training in Chennai

  6. When you want to succeed as much as you want to breathe, thats when you will be successful.

  7. Croma campus noida best Robotics Training in Noida and great robotics trainer with job placement support. Croma campus noida top IT course provide like (SAS, SAP, JAVA, ANDROID APPS, DOT NET, PHP) And more it service visit at croma campus

  8. Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
    Embedded Training in Chennai

  9. SAS Training Institute in noida- If you are looking for an institution where you can get SAS training at an affordable price then you are in the right place. Webtrackker offer advanced SAS Training in noida. As you know, these technologies are extremely popular and it is important for anyone seeking a career in the IT industry to gain the knowledge and skills needed to demonstrate their credibility. Our more services are SAS Training In Noida, SAS industrial training in noida, sas modeling training in noida, SAS Training In ghaziabad, SAS Training Institute in noida, SAS coaching institute in noida, SAS training institute in Ghaziabad, sas training institute, sas training center in noida.Training provided by our institute has been created to build a strong professional who can use and explore the tools needed to improve the performance of an organization.
    PHP Training Institute in Noida
    Sap Training Institute in Noida
    Sas Training Institute in Noida
    Hadoop Training Institute in Noida
    Oracle Training Institute in Noida
    Linux Training Institute in Noida
    Dot net Training Institute in Noida
    Salesforce training institute in noida
    Java training institute in noida

  10. If u r Interested in any automation courses contact us (91-9310096831) For Free DEMO Classes and Get your suitable Time Locked,,,

  11. Webtrackker Indirapuram, recognized among the top ten software testing training institute in Indirapuram, has a training module for beginners, intermediates and experts. If you are a university student, I.T professional or a project manager the best software testing training institute in Indirapuram offers the best training environment, veteran software testing trainers and flexible training schedules for complete modules. In addition, the best training institute for software testing training in Indirapuram asks for a value to the students' money rate. Students of all professions can pay the fee structure of the Software Testing courses.
    software testing institute in Indirapuram

  12. PLC Training ⁞ PLC Training in Noida, Delhi ⁞ PLC Programming Jobs in Delhi ⁞ #AllenBradley #Siemens #Mitsubishi #Delta #Omron
    Best Centre of PLC training in Noida - Learn advance Concept of PLC Programming, Timer Instructions, Counters Instructions, Compare Instructions, Math Instructions, Use the PLC programming software to download & upload programs and I/O tables.