问题描述
我没有〜/.R/Makevars
文件和
> tools::makevars_user()
character(0)
> tools::makevars_site()
character(0)
但是, R
必须从某处读取配置,因为包含 Rcpp
的 .cpp
文件在软件包 src中导出了代码>子目录编译正常.
Yet, R
must be reading the configuration from somewhere as .cpp
files containing Rcpp
exports in the package src
subdirectory compile fine.
我很想知道如何在 src
目录中编写 Makefile.win
,以便使 Rcpp
文件与 TMB
.cpp
文件.当前的生成文件如下:
I am interested to know how to write a Makefile.win
in the src
directory so that Rcpp
files continue to compile, alongside TMB
.cpp
files. Currently a makefile like:
all: fn1.dll fn2.dll
fn1.dll: fn1.cpp
Rscript --vanilla -e "TMB::compile('fn1.cpp')"
fn2.dll: fn2.cpp
Rscript --vanilla -e "TMB::compile('fn2.cpp')"
clean:
rm -rf *o
可以很好地编译 TMB
文件,并且实际上由以下建议: https://github.com/kaskr/adcomp/issues/43
works fine to compile TMB
files, and is in fact suggested by: https://github.com/kaskr/adcomp/issues/43
我试图修改Dirk在此处建议的 makefile ,但没有运气可复制 R
的默认行为,即使使用了新的测试包也是如此.
I tried to modify the makefile
suggested by Dirk here but had no luck to replicate R
's default behaviour even with a fresh new test package.
我的会话信息:
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
推荐答案
我仍然不知道如何使用 Makevars
来做我想做的事,本质上是:
I still have no idea how to use Makevars
to do what I want, which is to essentially:
- 通过
Build and Reload
包在Rstudio(Windows 7)中对所有Rcpp
导出文件执行正常的默认make
.在后台,此调用Rcpp :: compileAttributes()
,然后继续运行其他程序包构建命令. - 使用Rstudio
Build and Reload
进行另一个make
,除了现在它读取仅编译TMB
Makefile >代码.
- Do a normal default
make
in Rstudio (Windows 7) viaBuild and Reload
package for allRcpp
export files. Under the hood, this callsRcpp::compileAttributes()
then proceeds to run the other package building commands. - Do another
make
using RstudioBuild and Reload
, except now it reads theMakefile
that only compiles theTMB
code.
但是,我确实有一种解决方法.本质上, R扩展手册指出:
However, I do have a work-around. Essentially, the R extensions manual states that:
...
由于,用于编译 TMB
.cpp
文件的代码只是 R
命令,因此将它们集成到这样的目录中很容易文件:
Since, the code to compile the TMB
.cpp
files are simply R
commands, it is easy enough to integrate them into such a file:
# replicate default R
files <- Sys.glob(paste("*", SHLIB_EXT, sep=''))
libarch <- if (nzchar(R_ARCH)) paste('libs', R_ARCH, sep='') else 'libs'
dest <- file.path(R_PACKAGE_DIR, libarch)
dir.create(dest, recursive = TRUE, showWarnings = FALSE)
file.copy(files, dest, overwrite = TRUE)
# now do TMB files
cpp_files <- list.files('./TMB/', full.names = T, pattern = '*.cpp')
for (f in cpp_files) {
TMB::compile(f)
}
files <- Sys.glob(paste("./TMB/*", SHLIB_EXT, sep=''))
libarch <- if (nzchar(R_ARCH)) paste('libs', R_ARCH, sep='') else 'libs'
dest <- file.path(R_PACKAGE_DIR, libarch)
dir.create(dest, recursive = TRUE, showWarnings = FALSE)
file.copy(files, dest, overwrite = TRUE)
此文件读取并编译存储在子目录< pkgdir>/src/TMB
中的所有 TMP
类型的 .cpp
文件.,然后将< pkgdir>/src/
和&p; pkgdir>/src/TMB
中的所有后续 .dll
复制到安装中软件包的目录.
This file reads and compiles all TMP
type .cpp
files, stored in the sub-directory <pkgdir>/src/TMB
, and then copies all subsequent .dll
s in <pkgdir>/src/
and <pkgdir>/src/TMB
to the installation directory of the package.
请注意,这是可能的,但可能非常困难使用 Makevars
来获取将TMB文件存储在子目录中时完成编译.Dirk在矩阵包中推荐了该示例,但我有修改在那里的代码以执行我想要的操作是没有运气的.
Note, it is possible, but possibly very difficult to use Makevars
to get a compilation done when the TMB files are stored in a subdirectory. Dirk recommended the example in the matrix package, but I had no luck modifying the code there to do what I want.
这篇关于我如何查看和复制R默认的Makevars配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!