如何解决当我更新到 R 4.0.4 时,函数 Rcpp::match 不起作用
今天我更新到 R 4.0.4 并且 Rcpp::match 不能正常工作。我认为版本更新是原因,但不确定。任何建议都很棒。 (编辑:我刚刚在 R 3.6.3 中尝试过,以下代码运行良好)
(编辑 v2:将 Rstudio 更新到最新版本解决了这个问题)
下面是test_RcppMatch.cpp
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
Rcpp::IntegerVector test(Rcpp::CharacterVector SampleInModel,Rcpp::CharacterVector SampleInPlink)
{
Rcpp::IntegerVector posSampleInPlink = Rcpp::match(SampleInModel,SampleInPlink);
return posSampleInPlink;
}
// You can include R code blocks in C++ files processed with sourceCpp
// (useful for testing and development). The R code will be automatically
// run after the compilation.
//
/*** R
test(c(1,3,5,7,9),1:10)
*/
以下是错误信息
> Rcpp::sourceCpp('C:/Users/wenji/OneDrive/Desktop/test_RcppMatch.cpp')
> test(c(1,1:10)
Error in test(c(1,1:10) :
SET_VECTOR_ELT() can only be applied to a 'list',not a 'symbol'
以下是我的平台
> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] Rcpp_1.0.6 GRAB_0.0.1
loaded via a namespace (and not attached):
[1] compiler_4.0.4 tools_4.0.4 data.table_1.14.0
[4] packrat_0.5.0
解决方法
您的安装有什么有趣的地方吗?你可能有两个包的路径吗?
它在这里运行良好(R 4.0.4、Ubuntu 20.10、所有最新版本)
> Rcpp::sourceCpp("~/git/stackoverflow/66359002/question.cpp")
> test(c(1,3,5,7,9),1:10)
[1] 1 3 5 7 9
>
我基本上没有改变您的代码(但移动了两个卷曲,并删除了注释和 using
,因为您正确地为所有标识符添加了前缀)。
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::IntegerVector test(Rcpp::CharacterVector SampleInModel,Rcpp::CharacterVector SampleInPlink) {
Rcpp::IntegerVector posSampleInPlink = Rcpp::match(SampleInModel,SampleInPlink);
return posSampleInPlink;
}
/*** R
test(c(1,1:10)
*/
感谢您发布代码!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。