简体   繁体   English

外行R包开发说明

[英]Instructions for R package development for a layman

I have never done it, but want to develop R package for domestic use: 我从未做过,但是想开发家用R包:

For example following are my functions and a data: 例如以下是我的功能和数据:

# random DNA function 
randDNA = function(n){
paste(sample(c("A", "C", "T", "G"), n, replace = TRUE), collapse = "")
}
# DNA to RNA function 
dna2rna <- function(inputStr) { 
  if (!is.character(inputStr)) 
    stop("need character input") 
  is = toupper(inputStr) 
  chartr("T", "U", is) 
}

# complementary sequence function 
compSeq <-  function(inputStr){
 chartr("ACTG", "TGAC", inputStr)
 }

# example data
dnaseq1 <- c("ATTGTATCTGGGTATTTCCCTTAATTGGGGCCTTT")
dnaseq2 <- c("TGGGGTAAACCCGGTTTAAAATATATATATTTTT")
myseqdata <- data.frame(dnaseq1, dnaseq2)
save(myseqdata, file = "myseqdata.RData")

I tried to use utils package to develop framework, but had a problem: 我试图使用utils包来开发框架,但遇到了一个问题:

require(utils)

package.skeleton(list = c("randDNA","dna2rna", "compSeq", "myseqdata"),  
     name = "dnatool",environment = .GlobalEnv, path = "c:", force = FALSE)



Creating directories ...
    Creating DESCRIPTION ...
    Creating Read-and-delete-me ...
    Saving functions and data ...
    Making help files ...
    Error in .find.package(pkgName, lib.loc, verbose = verbose) : 
      there is no package called 'dnatool'
    Error in package.skeleton(list = c("randDNA", "dna2rna", "compSeq", "myseqdata"),  : 
      Error in .find.package(pkgName, lib.loc, verbose = verbose) : 
      there is no package called 'dnatool'

I have question regarding why I am getting this error. 我对为什么会收到此错误有疑问。 When I looked at C:\\dnatool I can see the folder created with the data and r functions. 当我查看C:\\ dnatool时,可以看到使用data和r函数创建的文件夹。

Now I want to compile to make it as package. 现在,我要进行编译以使其成为软件包。 As I am reading instructions, I used command prompt to pack it: I am using Windows 7. 在阅读说明时,我使用命令提示符对其进行打包:我正在使用Windows 7。

c:\> R CMD build dnatool 

Obviously does not work. 显然不起作用。 Is that due to above problem? 是由于上述问题吗? What path should I be in? 我应该走哪条路? Where there is R exe or C: or c:\\dnatool 如果存在R exe或C:或c:\\ dnatool

I will appreciate your help, if you can in R "layman" style help...thanks... 如果您能以R“外行”风格提供帮助,我将不胜感激...谢谢...

EDITS: I downloaded Rtools Rtools212.exe for R version 2.12.2 from: http://www.murdoch-sutherland.com/Rtools/ The tools are installed in C:\\Rtools 编辑:我从以下网站下载了Rtools Rtools212.exe for R版本2.12.2: http : //www.murdoch-sutherland.com/Rtools/该工具安装在C:\\ Rtools中

Directory of c:\Rtools

09/18/2011  08:08 AM    <DIR>          .
09/18/2011  08:08 AM    <DIR>          ..
09/18/2011  08:07 AM    <DIR>          bin
03/31/2010  09:50 AM            18,347 COPYING
09/18/2011  08:08 AM    <DIR>          MinGW
09/18/2011  08:09 AM    <DIR>          MinGW64
10/04/2010  10:21 AM             1,836 README.txt
10/07/2010  08:26 AM             3,676 Rtools.txt
09/18/2011  08:10 AM           728,889 unins000.dat
09/18/2011  08:07 AM         1,182,143 unins000.exe
               5 File(s)      1,934,891 bytes
               5 Dir(s)  36,454,875,136 bytes free

My skeleton of the package is in C:\\dnatool: 我的包的骨架在C:\\ dnatool中:

 Directory of c:\dnatool

09/17/2011  11:14 PM    <DIR>          .
09/17/2011  11:14 PM    <DIR>          ..
09/17/2011  11:14 PM    <DIR>          data
09/17/2011  11:14 PM               304 DESCRIPTION
09/17/2011  11:14 PM    <DIR>          man
09/17/2011  11:14 PM    <DIR>          R
09/17/2011  11:14 PM               385 Read-and-delete-me
               2 File(s)            689 bytes
               5 Dir(s)  36,455,153,664 bytes free

My R program is C:\\R.... 我的R程序是C:\\ R ....

My confusion is on the following instructions: where should execute them? 我对以下说明感到困惑:应该在哪里执行它们? I believe in command prompt. 我相信命令提示符。 Under which directory? 在哪个目录下?

* Run R CMD build to build the package tarball.
* Run R CMD check to check the package tarball. 

************Edits2: partial solution but with new error ****************************** The first round of problem has been solved with the suggestion for path. ************ Edits2:部分解决方案,但有新错误******************************第一轮问题已通过路径建议解决。 I have to manually change the path to: 我必须手动将路径更改为:

C:\Rtools\bin;C:\Rtools\perl\bin;C:\Rtools\MinGW\bin;
   C:\Program files\R\R-2.12.2\bin\x64;

I stored the skeleton to new directory. 我将骨架存储到新目录中。 By running the following command in command prompt: 通过在命令提示符下运行以下命令:

C:\Users\Owner\Documents\rpackages> Rcmd INSTALL --build dnatool

* installing to library 'C:/PROGRA~1/R/R-212~1.2/library'
* installing *source* package 'dnatool' ...
** R
** data
** preparing package for lazy loading
** help
Warning: C:/Users/Owner/Documents/rpackages/dnatool/man/dnatool-package.Rd:34: A
ll text must be in a section
Warning: C:/Users/Owner/Documents/rpackages/dnatool/man/dnatool-package.Rd:35: A
ll text must be in a section
*** installing help indices
Error in Rd_info(db[[i]]) : Rd files must have a non-empty \title.
See chapter 'Writing R documentation' in manual 'Writing R Extensions'.
* removing 'C:/PROGRA~1/R/R-212~1.2/library/dnatool

I was unsuccessful to create the package, the see the error in above window. 我没有成功创建包,请参见上面的窗口中的错误。 What does this mean. 这是什么意思。 I added relevent information line 34 and 35 of the file dnatool-package .Rd ...help ...thanks... 我添加了dnatool-package .Rd文件的relevent信息行34和35 ...帮助...感谢...

I am answering my question myself, so that it will remain unanswered, if fact partially it is. 我本人正在回答我的问题,因此即使实际上部分是事实,也将无法回答。 With the suggestions here , the problem has been solved by changing path by setting the following: 有了这里的建议,通过设置以下路径来解决此问题:

C:\Rtools\bin;C:\Rtools\perl\bin;C:\Rtools\MinGW\bin;
   C:\Program files\R\R-2.12.2\bin\x64;
I stored the skeleton to new directory.

By running the following command in command prompt: 通过在命令提示符下运行以下命令:

C:\Users\Owner\Documents\rpackages> Rcmd INSTALL --build dnatool

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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