JohnFarrell66 2023-03-23 20:50 采纳率: 100%
浏览 51
已结题

R语言中无法运行brm()函数

r语言,无法运行brms

img

img


在网上自己搜了很多,

Error in compileCode(f, code, language = language, verbose = verbose) : 
  C:\RBuildTools\4.2\x86_64-w64-mingw32.static.posix\bin/ld.exe: file4e8473fd1cc9.o:file4e8473fd1cc9.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\RBuildTools\4.2\x86_64-w64-mingw32.static.posix\bin/ld.exe: file4e8473fd1cc9.o:file4e8473fd1cc9.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\RBuildTools\4.2\x86_64-w64-mingw32.static.posix\bin/ld.exe: file4e8473fd1cc9.o:file4e8473fd1cc9.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\RBuildTools\4.2\x86_64-w64-mingw32.static.posix\bin/ld.exe: file4e8473fd1cc9.o:file4e8473fd1cc9.c
Error in sink(type = "output") : invalid connection

得知这一段报错很常见,与rstan与当前R的版本不匹配有关,但是我根据各种解决办法,包括更换R和Rtools的版本、安装cmdr等等,都无法解决。其中更换R的版本以后,我第一次换成了R4.0.0,把各种东西配置好以后,运行例子报错:

img


所以我又更换了R4.0.5版本,安装了rstan:

img


然后运行例子,这次显示:

img

一筹莫展了,其实没写出来的尝试还有很多,根据这些报错去官网还有可以找到的大部分帖子下面都找过解决办法,比如
https://zhuanlan.zhihu.com/p/577892365
这里提到的安装CmdStanR,通过原文给出的代码

install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

我无法下载:

img


但是我找到一个通过github下载的办法

# install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")

img


这一次下载成功了,然后根据指示检查C++工具链,并下载CmdStan

cmdstanr::check_cmdstan_toolchain(fix = TRUE)

cmdstanr::install_cmdstan()

第一行运行以后:

> cmdstanr::check_cmdstan_toolchain(fix = TRUE)
The C++ toolchain required for CmdStan is setup properly!

但是后面要安装cmdstan的时候就会失败

> cmdstanr::install_cmdstan()
The C++ toolchain required for CmdStan is setup properly!
* Latest CmdStan release is v2.31.0
* Installing CmdStan v2.31.0 in C:/Users/cj/Documents/.cmdstan/cmdstan-2.31.0
* Downloading cmdstan-2.31.0.tar.gz from GitHub...
Error: Download of CmdStan failed. Please try again.

vpn已经试过,没有什么改变。
总结一下就是运行brms包中的函数时就会报错,Error in sink(type = "output") : invalid connection,换版本之类的尝试过,请问还有没有什么解决办法,或者说我之前列举的尝试还有什么地方做错了,求一个解决办法,谢谢了

  • 写回答

2条回答 默认 最新

  • JohnFarrell66 2023-03-26 19:29
    关注

    目前已经解决了,方法参照https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows#rstan-compatibility%E8%BF%99%E9%87%8C%E6%8F%90%E5%88%B0%E7%9A%84%EF%BC%8C
    其实这个方法我很早之前就试过 ,但是之前显示的是报错

    Error in download.file(url, destfile, method, mode = "wb", ...) : 
      download from 'https://mc-stan.org/r-packages/bin/windows/contrib/4.2/rstan_2.26.16.zip' failed
    Warning in install.packages :
      下载程序包‘rstan’时出了问题
    
    

    但是今天换了一个网络,重启了R以后莫名安装成功了......之后就可以正常运行了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月3日
  • 已采纳回答 3月26日
  • 创建了问题 3月23日

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决