错误“.onLoad 在 loadNamespace() for 'tcltk' 中失败"; [英] Error ".onLoad failed in loadNamespace() for 'tcltk'"

查看:112
本文介绍了错误“.onLoad 在 loadNamespace() for 'tcltk' 中失败";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于如何有效地将任何类型的外部包加载到 R 中的一般性问题.我发现许多详细说明此信息的来源根本不够,但我不会提及这些相应的 URL.我之前已经成功地将外部包加载到 R 中,但是我在加载 fgui 包时遇到了困难.

I have a general question about how to effectively load any kind of external package into R. I have found that many sources detailing this information are simply insufficient, but I will leave out mentioning those respective URLs. I have successfully loaded external packages into R before, but I am having difficulties loading the fgui package.

在我的特定情况下,我无法将库 fgui 加载到 R Studio.首先,我使用以下命令直接从 CRAN 下载:

In my specific case, I cannot load the library fgui into R Studio. First I download directly from CRAN with the command:

install.packages("fgui", lib="~/Documents/R_dir")

这对我来说很好用.我的工作目录设置为 ~/Documents/R_dir

This works fine for me. My working directory is set to ~/Documents/R_dir

我使用的下一个命令是:

The next command I use is:

library("fgui", lib.loc="~/Documents/R_dir")

我得到的错误是:

Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so, 10): Library not loaded: /opt/X11/lib/libX11.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so
Reason: image not found
Error: package or namespace load failed for ‘fgui’

我检查了线程尝试加载库时出错(ggplot2) in R"但它没有回答我的问题.

I have examined the thread "Error when trying to load library(ggplot2) in R" but it did not answer my question.

请帮助我提供任何建议以使包 fgui 在 R Studio 中正常工作,并随时解决将外部包有效加载到 R 中的更一般问题.

Please help me with any suggestions to get the package fgui to work properly in R Studio and feel free to address the more general issue of effectively loading external packages into R.

推荐答案

tcltk 不是典型的包.它可能已经安装在您的系统上,并且无法使用通常的 install.packages 过程进行安装,因为它不在 CRAN 上(就像 R 附带的基本软件包,例如 stats代码>等).另外,tcltk2tcltk 不同;这是一个扩展(并依赖于)tcltk 功能的包.

tcltk is not a typical package. It's probably already installed on your system and it cannot be installed using the usual install.packages procedure because it is not on CRAN (just like the base packages that come with R, like stats, etc.). Also, tcltk2 is not the same as tcltk; that is a package that expands upon (and depends on) the functionality of tcltk.

所以,从这个开始:

> capabilities("tcltk")
tcltk 
 TRUE

如果返回 FALSE,则意味着您的 R 不是用 tcltk 支持构建的.你没有说你用的是什么操作系统,所以有点难帮你.

If that comes back FALSE it means that your R was not built with tcltk support. You don't say what OS you're using, so it's a little bit difficult to help you.

也就是说,如果您使用的是 Linux,则需要重新构建 R 支持 tcltk.这应该是相对简单的.基本上,确保 Tcl 和 tk 在您的系统上的标准位置可用(类似于 sudo apt-get install tcl8.5-dev tk8.5-dev),然后按照常规程序重建 R.

That said, if you're on Linux, you need to rebuild R with tcltk support. This should be relatively straightforward. Basically, make sure Tcl and tk are available on your system in a standard location (something like sudo apt-get install tcl8.5-dev tk8.5-dev) and then rebuild R per usual procedures.

如果您使用的是 Mac OS,您会遇到与 John Fox 在这里描述了与 Rcmdr 相关的内容.简而言之,这可能是以下两种情况之一:

If you're on Mac OS, you're encountering the same error that John Fox describes here in relation to Rcmdr. In short, it's probably one of two things:

  1. 与安装 Tcl 的目录相关的文件权限问题.引用 Fox 的话:您可以通过在 R 命令提示符下发出以下命令来验证此问题的根源:

  1. A file permission issue related to the directory where you have Tcl installed. To quote Fox: "You can verify the source of this problem by issuing the following command at the R command prompt:

system("ls -ld /usr/local /usr/local/lib /usr/local/lib/libtcl*")
# ls: /usr/local/lib: Permission denied
# ls: /usr/local/lib/libtcl*: Permission denied
# drwx------  8 root  wheel  272 Sep 24 10:21 /usr/local

如果系统命令的输出如上所示,您应该转到终端并执行以下操作:sudo chmod -R a+rX/usr/local 并输入您的密码以更改目录权限.

If the output of the system command looks like the above, you should go to Terminal and do the following: sudo chmod -R a+rX /usr/local and enter your password to change directory permissions.

  1. 您的 X-Windows 版本已过时.尝试运行 Mac OS 软件更新.

也可以通过创建符号链接来解决 as在这个答案中描述.

It may also be solvable by creating a symbolic link as described in this answer.

这不应该出现在 Windows 上,除非您从没有 tcl/tk 支持的源代码构建 R.

This should never come up on Windows, unless you built R from source without tcl/tk support.

这篇关于错误“.onLoad 在 loadNamespace() for 'tcltk' 中失败";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆