【问题标题】:Function Rcpp::match does not work when I updated to R 4.0.4当我更新到 R 4.0.4 时,函数 Rcpp::match 不起作用
【发布时间】:2021-02-24 21:20:09
【问题描述】:

今天我更新到 R 4.0.4 并且 Rcpp::match 不能正常工作。我认为版本更新是原因,但不确定。任何建议都很棒。 (编辑:我刚刚在 R 3.6.3 中尝试过,以下代码运行良好)

(EDIT 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,3,5,7,9),1:10)
Error in test(c(1, 3, 5, 7, 9), 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  

【问题讨论】:

    标签: rcpp


    【解决方案1】:

    你的安装有什么好玩的吗?你可能有两个包路径吗?

    在这里运行良好(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
    > 
    

    我基本上没有改变您的代码(但移动了两个花括号,并删除了 cmets 和 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,3,5,7,9),1:10)
    */
    

    感谢您发布代码!

    【讨论】:

    • 感谢您的回复。我刚刚将我的 Rstudio 更新到了最新版本,并且没有出现错误。更新Rstudio的想法来自stackoverflow.com/questions/61860755/…
    • 我非常怀疑它与它有什么关系,但是嘿 a)你现在可以工作了,所以谁在乎呢 b)我也倾向于运行 RStudio 日报(可能每月更新一次)所以我可能有反正一直在更新版本...
    猜你喜欢
    • 2018-05-16
    • 1970-01-01
    • 2021-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    相关资源
    最近更新 更多