当我R从终端打开时,我可以使用 Tab 键自动完成功能和对象。通过在函数和之后按Tab 键(,函数参数将被列出。但是,在 Ubuntu 中,这些参数似乎是根据它们的声明方式排序的;在 中macos,它们按字母顺序排列。
在 MacO 下:
> findInterval(
all.inside= left.open= rightmost.closed= vec= x=
Run Code Online (Sandbox Code Playgroud)
在 Ubuntu 下:
> findInterval(
x= vec= rightmost.closed= all.inside= left.open=
Run Code Online (Sandbox Code Playgroud)
我想在我的 Mac 上拥有 Ubuntu 行为。我从终端查看了readline选项(不确定是否相关)man readline,但找不到任何有用的东西。
要求
正如您所观察到的,安装 R-4.0.4.pkg 时,R 按字母顺序排列参数。但是,当 R 与 Homebrew 一起安装时,它们会按预期顺序显示。
因此一种可能的解决方案是卸载 R 并通过 Homebrew 安装它。
卸载R
rm /usr/local/bin/{R,RScript}
sudo rm -r /Applications/R.app
sudo rm -r /Library/Frameworks/R.framework
sudo pkgutil --regexp --forget 'org\.R-project*'
Run Code Online (Sandbox Code Playgroud)
通过 Homebrew 安装 R
brew install R
Run Code Online (Sandbox Code Playgroud)
对我来说,它显示了一些目录(例如 /usr/local/share/info)对于我的用户不可写的错误。复制/粘贴brew推荐的内容,对我来说例如:
sudo chown -R $(whoami) /usr/local/lib/pkgconfig /usr/local/share/info /usr/local/share/man/man3 /usr/local/share/man/man5
Run Code Online (Sandbox Code Playgroud)
然后重复命令:
brew install R
Run Code Online (Sandbox Code Playgroud)
这次它成功了,它还安装了所有依赖项,如 openblas、readline、openssl@1.1 等。
现在,当您启动 R 时,它会显示一系列警告,例如Setting LC_COLLATE failed. 假设您使用 zsh,创建或编辑 ~/.zshrc 并添加以下行
export LC_ALL=en_US.UTF-8
Run Code Online (Sandbox Code Playgroud)
测试
现在打开一个新的终端窗口并输入 R。如果您使用自动完成功能,findInterval(您将看到预期的行为,请参见屏幕截图:
为什么这两种安装方式不同?
您可以查看brew 与R-4.0.4.pkg 变体的配置。对于brew,你可以在/usr/local/Cellar/r/4.0.4_2/lib/R/etc/Makeconf 中找到它,它看起来像这样:
configure '--prefix=/usr/local/Cellar/r/4.0.4_2' '--enable-memory-profiling' '--without-cairo' '--without-x' '--with-tcl-config=/usr/local/opt/tcl-tk/lib/tclConfig.sh' '--with-tk-config=/usr/local/opt/tcl-tk/lib/tkConfig.sh' '--with-aqua' '--with-blas=-L/usr/local/opt/openblas/lib -lopenblas' '--enable-R-shlib' '--disable-java' 'PKG_CONFIG_PATH=/usr/local/opt/gmp/lib/pkgconfig:/usr/local/opt/isl/lib/pkgconfig:/usr/local/opt/mpfr/lib/pkgconfig:/usr/local/opt/jpeg/lib/pkgconfig:/usr/local/opt/libpng/lib/pkgconfig:/usr/local/opt/openblas/lib/pkgconfig:/usr/local/opt/pcre2/lib/pkgconfig:/usr/local/opt/readline/lib/pkgconfig:/usr/local/opt/openssl@1.1/lib/pkgconfig:/usr/local/opt/tcl-tk/lib/pkgconfig:/usr/local/opt/xz/lib/pkgconfig' 'PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.15' 'CC=clang' 'CFLAGS=-Wno-implicit-function-declaration' 'LDFLAGS=-L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/xz/lib' 'CPPFLAGS=-I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/xz/include' 'CXX=clang++' 'OBJC=clang'
Run Code Online (Sandbox Code Playgroud)
对于 Framework R-4.0.4.pkg 变体,您可以在文件 /Library/Frameworks/R.framework/Resources/etc/Makeconf 中找到信息:
configure 'CC=clang -mmacosx-version-min=10.13' 'CXX=clang++ -mmacosx-version-min=10.13' 'OBJC=clang -mmacosx-version-min=10.13' 'FC=gfortran -mmacosx-version-min=10.13' 'F77=gfortran -mmacosx-version-min=10.13' 'CFLAGS=-Wall -g -O2' 'CXXFLAGS=-Wall -g -O2' 'OBJCFLAGS=-Wall -g -O2' 'FCFLAGS=-Wall -g -O2' 'F77FLAGS=-Wall -g -O2' '--enable-memory-profiling' '--x-libraries=/opt/X11/lib' '--x-includes=/opt/X11/include' '--enable-R-framework' '--build=x86_64-apple-darwin17.0' 'build_alias=x86_64-apple-darwin17.0' 'PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig'
Run Code Online (Sandbox Code Playgroud)
请注意brew 变体中readline 和gettext 的CPPFLAGS 和LDFLAGS。
测试:将 CPPFLAGS/LDFLAGS 添加到 R-4.0.4.pkg 变体
只是为了证实需要这些编译/链接标志的理论,R 是从此处的源代码构建的。
首先,如果系统上尚不存在某些依赖项,则需要这些依赖项。
Xcode
XQuartz-2.8.0.dmg from https://www.xquartz.org
brew install gfortran
brew install xz
brew install cairo
brew install pcre2
brew install libtiff libjpeg
Run Code Online (Sandbox Code Playgroud)
从其中一个镜像下载源代码 R-4.0.4.tar.gz。
修改后的配置命令现在如下所示:
./configure 'CC=clang -mmacosx-version-min=10.13' 'CXX=clang++ -mmacosx-version-min=10.13' 'OBJC=clang -mmacosx-version-min=10.13' 'FC=gfortran -mmacosx-version-min=10.13' 'F77=gfortran -mmacosx-version-min=10.13' 'CFLAGS=-Wall -g -O2' 'CXXFLAGS=-Wall -g -O2' 'OBJCFLAGS=-Wall -g -O2' 'FCFLAGS=-Wall -g -O2' 'F77FLAGS=-Wall -g -O2' '--enable-memory-profiling' '--x-libraries=/opt/X11/lib' '--x-includes=/opt/X11/include' '--enable-R-framework' '--build=x86_64-apple-darwin17.0' 'build_alias=x86_64-apple-darwin17.0' 'PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig' 'CPPFLAGS=-I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/xz/include' 'LDFLAGS=-L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/xz/lib' 'CFLAGS=-Wno-implicit-function-declaration'
Run Code Online (Sandbox Code Playgroud)
之后就可以调用
make
Run Code Online (Sandbox Code Playgroud)
确保您在执行最后一步之前已创建备份。最后用这个命令
sudo make install
Run Code Online (Sandbox Code Playgroud)
可以创建或覆盖 /Library/Frameworks/R.framework。现在调用/Library/Frameworks/R.framework/Resources/bin/R显示了有关函数参数自动完成的预期行为,并且还提供了预期的功能。