面向外行的 R 包开发说明

发布于 2024-12-05 01:56:00 字数 4278 浏览 1 评论 0原文

我从来没有这样做过,但想开发供国内使用的R包:

例如以下是我的功能和数据:

# 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")

我尝试使用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'

我对为什么得到这个有疑问错误。当我查看 C:\dnatool 时,我可以看到使用 data 和 r 函数创建的文件夹。

现在我想编译使其成为包。当我阅读说明时,我使用命令提示符来打包它:我使用的是 Windows 7。

c:\> R CMD build dnatool 

显然不起作用。是因为上面的问题吗?我应该走哪条路?哪里有 R exe 或 C: 或 c:\dnatool

我将感谢您的帮助,如果您能以 R“外行”风格帮助...谢谢...

编辑: 我从以下位置下载了 R 版本 2.12.2 的 Rtools Rtools212.exe: 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

我的包框架位于 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

我的 R 程序是 C:\R....

我的困惑在于以下说明:应该在哪里执行它们?我相信命令提示符。在哪个目录下?

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

**********Edits2:部分解决方案,但出现新错误 ****************************** 第一轮问题已经通过路径建议解决了。我必须手动将路径更改为:

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

我将骨架存储到新目录。通过在命令提示符中运行以下命令:

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

我未能成功创建包,请在上面的窗口中看到错误。这是什么意思呢。我添加了文件 dnatool-package 的第 34 和 35 行相关信息 .路...帮助...谢谢...

I have never done it, but want to develop R package for domestic use:

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:

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.

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.

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

I will appreciate your help, if you can in R "layman" style help...thanks...

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

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:

 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....

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. 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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦言归人 2024-12-12 01:56:00

我自己回答我的问题,这样它就不会得到解答,如果事实部分得到解答的话。根据此处的建议,通过设置以下内容更改路径已解决问题:

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.

通过在命令提示符中运行以下命令:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文