我一直在编写大量供个人使用的代码,最后我意识到我应该将所有这些都包含在一个包中,我可以将其加载到其中,而不是每次都复制并粘贴它。
我按照以下教程创建了一个基本包。
https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/
据我所知,实际创作元素一切顺利。以下是结果截图:
猫文件夹:
/cats/R 文件夹
/cats/man 文件夹
当我想运行该行时,问题就出现了:
install("cats")
当我尝试这样做时,出现以下错误:
Installing cats
"C:/PROGRA~1/R/R-33~1.1/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL "/Documents/cats" --library="C:/Users/Aodhán/Documents/R/win-library/3.3" --install-tests
* installing *source* package 'cats' ...
Warning in file(file, if (append) "a" else "w") :
cannot open file 'C:/Users/Aodhán/Documents/R/win-library/3.3/cats/DESCRIPTION': No such file or directory
Error in file(file, if (append) "a" else "w") :
cannot open the connection
ERROR: installing package DESCRIPTION failed for package 'cats'
* removing 'C:/Users/Aodhán/Documents/R/win-library/3.3/cats'
Error: Command failed (1)
这个错误发生在我自己的包上,但如果我运行命令也会发生:
devtools::install_github("klutometis/roxygen")
如有任何建议,我们将不胜感激。
编辑:我的用户名中可能包含字符 á 吗?
编辑2:描述文件是:
Package: cats
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "[email protected]", role = c("aut", "cre"))
Maintainer: Aodhán O'Leary
Author: Aodhán O'Leary [aut, cre]
Description: What the package does (one paragraph).
Depends: R (>= 3.3.1)
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
Sys.getenv("R_HOME")
返回“C:/PROGRA~1/R/R-33~1.1”
Sys.getenv("R_LIBS_USER")
返回“C:\Users\Aodhán\Documents/R/win-library/3.3”
Sys.getenv("R_HOME")
返回“C:\Users\Aodhán\Documents”
devtools::build("cats")
创建“cats_0.0.0.9000.tar.gz”
install.packages("../cats_version.tar.gz")
返回与上面相同的错误
注意:这是在 Win10 机器上,使用 R 3.3.1,我很抱歉没有在顶部提及。昨天写这篇文章的时候很累。
编辑 3:这是使用以下命令的结果:R CMD build cats
后跟 R CMD check cats
00检查:
- using log directory 'C:/Users/Aodhán/Documents/cats.Rcheck'
- using R version 3.3.1 (2016-06-21)
- using platform: x86_64-w64-mingw32 (64-bit)
- using session charset: ISO8859-1
- checking for file 'cats/DESCRIPTION' ... OK
- this is package 'cats' version '0.0.0.9000'
- package encoding: UTF-8
- checking package namespace information ... OK
- checking package dependencies ... OK
- checking if this is a source package ... OK
- checking if there is a namespace ... OK
- checking for .dll and .exe files ... OK
- checking for hidden files and directories ... NOTE Found the following hidden files and directories: .gitignore These were most likely included in error. See section 'Package structure' in the 'Writing R Extensions' manual.
- checking for portable file names ... OK
- checking whether package 'cats' can be installed ... ERROR Installation failed. See 'C:/Users/Aodhán/Documents/cats.Rcheck/00install.out' for details.
- DONE
Status: 1 ERROR, 1 NOTE
00install.out
- installing source package 'cats' ...
Warning in file(file, if (append) "a" else "w") : cannot open file 'C:/Users/Aodhan/Documents/cats.Rcheck/cats/DESCRIPTION':
No such file or directory
Error in file(file, if (append) "a" else "w") : cannot open the connection
ERROR: installing package DESCRIPTION failed for package 'cats'
- removing 'C:/Users/Aodhán/Documents/cats.Rcheck/cats'
最佳答案
问题是我名字中的特殊字符 á。当我将它放在 C:\目录中并运行 R CMD build cats
和 R CMD check cats
时,它传递了该错误(尽管后来 pdf 出现了错误) - 我会看看我是否可以自己解决这个问题)。
我会尝试将此作为错误发布。比较烦人。应该早点想到那个测试。
关于r - 无法安装我创建的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42678808/