无法安装我创建的包

Cannot install my created packages

我写了很多代码供个人使用,最后我意识到我真的应该将所有这些都包含在一个我可以加载的包中,而不是每次都复制和粘贴它.

我按照以下教程创建了一个基本包。

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:The描述文件是:

Package: cats

Title: What the Package Does (one line, title case)

Version: 0.0.0.9000

Authors@R: person("First", "Last", email = "first.last@example.com", 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") returns "C:/PROGRA~1/R/R-33~1.1"

Sys.getenv("R_LIBS_USER") returns "C:\Users\Aodhán\Documents/R/win-library/3.3"

Sys.getenv("R_HOME") returns "C:\Users\Aodhán\Documents"

devtools::build("cats") 创建 "cats_0.0.0.9000.tar.gz"

install.packages("../cats_version.tar.gz") returns 同上错误

注意:这是在 Win10 机器上,使用 R 3.3.1,我很抱歉没有在上面提到。昨天写post的时候好累

编辑 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'

正在安装源码包.. 指定回购和类型很重要

  • 将包转换成package_name.tar.gz
  • 双击
    中的.Rproj文件进入项目环境 您的项目并单击构建 -> 构建源包以构建 tar.gz 文件
  • install.packages("full_path/package_name.tar.gz", repo = NULL, type = "source")

问题出在我名字中的特殊字符 á。当我把它放在 C:\ 目录和 运行 R CMD build catsR CMD check cats 时,它传递了那个错误(尽管后来 pdf 出现错误 - 我会看看我是否可以自己解决)。

我会尝试 post 这是一个错误。有点烦人。早该想到那个测试了。

我最近 运行 在两台不同的计算机上遇到过这个问题(R 版本 3.5.2)。我现在没有完整、准确的错误消息,但它包含以下两个片段:

Error in writeLines(paste0(c(out[is_not_empty]), eor), file, useBytes = useBytes) :
(converted from warning) invalid char string in output conversion

ERROR: installing package DESCRIPTION failed for package

我认为问题出在我的 .Rprofile 文件中存在特殊字符。无论如何,我一直想摆脱那个文件(为了重现性),这样做解决了问题。

要在 R 中执行此操作,下面的代码将 (1) 复制您的 .Rprofile 并将其另存为 .Rprofile-old(如果您想use/restore 稍后)然后 (2) 删除你的 .Rprofile.

## copy backup of .Rprofile
file.copy("~/.Rprofile", "~/.Rprofile-old")

## delete .Rprofile
unlink("~/.Rprofile")

完成 运行 上述代码后,重新启动 R,问题将 [希望] 得到解决!