我想在R包中包含一个Fortran子例程。我一直只使用devtools和roxygen构建包(所以我的知识可能非常有限)。我收到一个错误,阻止我在构建它之后安装它不是Win32应用程序...
我正在使用Rtools 3.3。我的会话信息:
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] roxygen2_5.0.1 devtools_1.9.1
loaded via a namespace (and not attached):
[1] magrittr_1.5 tools_3.2.2 Rcpp_0.12.1 memoise_0.2.1 stringi_1.0-1 stringr_1.0.0 digest_0.6.8
要初步构建软件包,我运行它:
library(devtools)
library(roxygen2)
setwd("C:/panterasBox")
create("myPack")
setwd("C:/panterasBox/myPack")
dir.create("C:/panterasBox/myPack/src")
这是fortran代码,保存为/src
文件中的myFunc.f:
subroutine myFunc(x)
implicit none
real(8) x
x = x + 2
return
end
我用来调用它的R包装器(保存在/R
文件中):
#' @title A test
#' @description a test function.
#' @param x this is a number
#' @useDynLib myPack
#' @export
myFunc <- function(x){
if (!is.loaded('myFunc')) {
dyn.load("/src/myPack.dll")
}
myCall <- NULL
myCall <- .Fortran("myFunc", x=as.double(x), PACKAGE="myPack")
return(myCall$x)
}
现在,要创建文档并安装软件包,我运行它:
> document()
Updating myPack documentation
Loading myPack
Re-compiling myPack
"C:/Users/pantera/DOCUME~1/R/R-32~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore CMD INSTALL \
"C:\panterasBox\myPack" --library="C:\Users\pantera\AppData\Local\Temp\RtmpQdJJko\devtools_install_1df837dd6c29" --no-R \
--no-data --no-help --no-demo --no-inst --no-docs --no-exec --no-multiarch --no-test-load
* installing *source* package 'myPack' ...
** libs
gfortran -m64 -O2 -mtune=core2 -c myFunc.f -o myFunc.o
gcc -m64 -shared -s -static-libgcc -o myPack.dll tmp.def myFunc.o -Ld:/RCompile/r-compiling/local/local320/lib/x64 -Ld:/RCompile/r-compiling/local/local320/lib -lgfortran -LC:/Users/pantera/DOCUME~1/R/R-32~1.2/bin/x64 -lR
installing to C:/Users/pantera/AppData/Local/Temp/RtmpQdJJko/devtools_install_1df837dd6c29/myPack/libs/x64
* DONE (myPack)
First time using roxygen2. Upgrading automatically...
Updating roxygen version in C:\panterasBox\myPack/DESCRIPTION
Writing NAMESPACE
Writing myFunc.Rd
> install("myPack")
Installing myPack
"C:/Users/pantera/DOCUME~1/R/R-32~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore CMD INSTALL \
"C:/panterasBox/myPack" --library="C:/Users/pantera/Documents/R/R-3.2.2/library" --install-tests
* installing *source* package 'myPack' ...
** libs
*** arch - i386
make: Nothing to be done for `all'.
installing to C:/Users/pantera/Documents/R/R-3.2.2/library/myPack/libs/i386
*** arch - x64
make: Nothing to be done for `all'.
installing to C:/Users/pantera/Documents/R/R-3.2.2/library/myPack/libs/x64
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Users/pantera/Documents/R/R-3.2.2/library/myPack/libs/i386/mypack.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/pantera/Documents/R/R-3.2.2/library/myPack'
Error: Command failed (1)
我还尝试使用R CMD build myPack
然后R CMD check myPack_*tar.gz
通过命令行构建和检查包。我做的唯一错误是关于我的LaTeX包。
感谢您阅读此内容,感谢您提供的任何帮助。
免责声明:我之前曾问过这个问题,但我想以“最小化的方式”再次提问。
答案 0 :(得分:5)
很明显,这是一个架构问题。看起来你的软件包的x64版本(可能是你需要的)已经成功构建,但是x86构建,因此整个任务失败了。请尝试以下方法:
--no-multiarch
选项添加到install
来电。这将告诉RCmd
不要为x86构建,因为你的主拱是x64。--no-test-load
选项添加到install
来电。这将告诉RCmd
不要通过加载包的成功来判断构建任务的成功。 library('myPack')
手动加载包,看看它是否有效。总结一下,将您的install
来电替换为:
install('myPack', args=c('--no-multiarch','--no-test-load'))
library('myPack')
答案 1 :(得分:0)
看起来您正在加载dyn.load("/src/myPack.dll")
但在安装过程中它正在寻找:
'C:/Users/pantera/Documents/R/R-3.2.2/library/myPack/libs/i386/mypack.dll'
(即没有资本P)
*对不起,我没有足够的代表将其作为评论。