[英]How to create an R package nested in git directory
I used to be able to build my R packages within my github repo, but the devtools functions have been deprecated and replaced with new functions that won't allow me to do this anymore.我曾经能够在我的 github 存储库中构建我的 R 包,但是 devtools 函数已被弃用并替换为不允许我再这样做的新函数。
I was previously using devtools::setup('NewPackage', check=FALSE)
in my directory /home/User/NewPackage/
, to create my R package /home/User/NewPackage/NewPackage
我以前在我的目录
/home/User/NewPackage/
使用devtools::setup('NewPackage', check=FALSE)
来创建我的 R 包/home/User/NewPackage/NewPackage
The new alternative gives the following error新的替代方案给出了以下错误
usethis::create_package('NewPackage')
#New project 'NewPackage' is nested inside an existing project '/home/User/NewPackage/'
#This is rarely a good idea. Do you wish to create anyway?
#1: Negative
#2: I agree
#3: No way
I had automated my package creation, but this new function breaks the code in all of my packages.我已经自动化了我的包创建,但是这个新功能破坏了我所有包中的代码。
I have posted this as a bug https://github.com/r-lib/usethis/issues/553我已将此作为错误发布https://github.com/r-lib/usethis/issues/553
But I am still looking for a work around or any way to automatically submit I agree
?但我仍在寻找解决方法或任何方式自动提交
I agree
吗?
There are also hidden files, such as .Rd2pdf12059
, in my /home/User/NewPackage/
directory我的
/home/User/NewPackage/
目录下也有隐藏文件,比如.Rd2pdf12059
Until this is fixed, I have just copied the old devtools source code and removed what I didn't like.在修复之前,我只是复制了旧的 devtools 源代码并删除了我不喜欢的内容。
Not the cleanest way of doing things, but you could use testthat::with_mock
to trick check_not_nested
:不是最干净的做事方式,但您可以使用
testthat::with_mock
来欺骗check_not_nested
:
testthat::with_mock(
check_not_nested = function(path, name) return(),
usethis::create_package('NewPackage2'),
.env = "usethis"
)
As the testthat::with_mock
function is now deprecated, and the functions from mockr
or mockery
cannot replace functions in other packages, I have found the following to work.由于
testthat::with_mock
功能现在已经过时,并从功能mockr
或mockery
不能在其他包替换功能,我发现以下工作。
Note that check_not_nested
is now named challenge_nested_project
in the usethis
package (version 2.0.1)请注意,在
usethis
包(2.0.1 版)中check_not_nested
现在被命名为challenge_nested_project
challenge_nested_project <- function(path, name) return()
rlang::env_unlock(env = asNamespace('usethis'))
rlang::env_binding_unlock(env = asNamespace('usethis'))
assign('challenge_nested_project', challenge_nested_project, envir = asNamespace('usethis'))
rlang::env_binding_lock(env = asNamespace('usethis'))
rlang::env_lock(asNamespace('usethis'))
This code does not temporarily replace the function until the package is unloaded and loaded again, and the rlang
functions are listed as experimental, so handle with care and results might change in the future.此代码在卸载并再次加载包之前不会临时替换该函数,并且
rlang
函数被列为实验性的,因此请谨慎处理,结果将来可能会发生变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.