CRAN允许Mac用户在此安装带有.pkg
文件的R:
https://cran.r-project.org/bin/macosx/
据推测,这是通过在R的编译版本上运行pkgbuild生成的。有谁知道此进程的源脚本位于何处?或者如何将这个过程伪复制?
答案 0 :(得分:1)
使R捆绑的命令的源不可用。但是,您可以下载生成的捆绑包,并使用OS X pkg实用程序(pkgbuild
,pkgutil
,productbuild
)对其进行修改以包含您可能需要的其他内容。例如,下面的脚本下载分布式捆绑包,将用户R库中的所有包添加到其中,然后重新捆绑以进行分发。
wget https://cloud.r-project.org/bin/macosx/R-3.5.0.pkg
BUILD_DIR=build
mkdir $BUILD_DIR
# Unpack the CRAN R distribution
pkgutil --expand R-3.5.0.pkg $BUILD_DIR/tmp_pkg
# Now to add more default packages to the R package payload
# First extract the payload
pushd $BUILD_DIR/tmp_pkg/r.pkg/
cat Payload | gzip -d | cpio -id
# Copy all of the users R packages into this
# folder for distribution
R_LIB_DIR=$(sed -e 's/\[1\] \"//' -e 's/\"//' <<< $(RScript -e '.libPaths()'))
R_PAYLOAD_DIR="R.framework/Resources/library"
for dirname in $R_LIB_DIR/*
do
pkg_name=$(basename $dirname)
if [ ! -d $R_PAYLOAD_DIR/$pkg_name ]
then
echo "Moving package:" $pkg_name
cp -r $dirname $R_PAYLOAD_DIR/$pkg_name
fi
done
# Let's remove the debug symbols and their associated plists for compiled code in R
# packages, as they bloat the installation
find $R_PAYLOAD_DIR -name '*so.dSYM' -prune -exec rm -rf {} \;
# Now build a new r.pkg
pkgbuild --component R.framework --scripts Scripts/ \
--identifier org.r-project.R.el-capitan.fw.pkg \
--version 30574626 \ # You may want to change this
--install-location /Library/Frameworks \
../../r.pkg
popd
# Remove original one we've replaced
rm -rf $BUILD_DIR/tmp_pkg/r.pkg
# Flatten remaining components distributed with R
# (necessary to repackage it all).
for fname in $BUILD_DIR/tmp_pkg/*.pkg
do
bname=$(basename $fname)
pkgutil --flatten $fname $BUILD_DIR/$bname
done
mv $BUILD_DIR/tmp_pkg/Resources $BUILD_DIR/
mv $BUILD_DIR/tmp_pkg/Distribution $BUILD_DIR/
(cd $BUILD_DIR; productbuild --distribution Distribution --resources Resources ../R-With-Your-Stuff.pkg)