简体   繁体   中英

Creating a package in R using RStudio

I've created a bunch of files:

  • init.r
  • auth.r
  • class.r
  • modules/status.r
  • modules/mgmt.r
  • modules/core.r
  • modules/mcf.r

The source of the init.r file is:

# initiation of package

# include libraries
library(RCurl);
library(rjson);

# include files
source('auth.r');
source('class.r');

# extend class
source('modules/status.r');
source('modules/mgmt.r');
source('modules/core.r');
source('modules/mcf.r');

How do I go about creating a package out of this? The init.r file obviously needs to be initiated first.

Start with following the steps in this video:

Build an R Package in under 2 minutes with RStudio

Then read more about RStudio's Package Development feature, and also Hadley Wickam's Package basics .

See Writing R Extensions for the process of making a package. You might want to use package.skeleton to get started.

But essentially,

  • get rid of your init.r file,
  • put all your other .R files in the R directory
  • write Depends: RCurl, rjson in your DESCRIPTION file.

1. Build the prerequisites: To build R Packages using RStudio, you should have the following prerequisites like R, RStudio, Rtools, Basic MikTex, roxygen2 and devtools packages.

2. Create the RPackage project in RStudio and add all your R files (init.r,auth.r,class.r,modules/status.r,modules/mgmt.r,modules/core.r,modules/mcf.r) under the R folder of the project.

3. Add the documentation by editing the package description file. Build the project and now your package is ready to use.

it won't take more than 15 minutes to build a simple package. If you wish to have step by step explanation to create a simple package, please visit this blog. https://veeramaninatarajanmca.wordpress.com/2017/02/10/how-to-create-a-simple-package-in-r-using-rstudio/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM