繁体   English   中英

R如何制作.pkg文件以在Mac OS X上安装?

[英]How does R make the .pkg file for installation on Mac OS X?

CRAN允许Mac用户使用.pkg文件安装R,可在此处下载:

https://cran.r-project.org/bin/macosx/

大概是通过在R的编译版本上运行pkgbuild生成的。有人知道此进程的源脚本位于何处吗? 或者该过程如何进行伪复制?

形成R捆绑包的命令的源不可用。 但是,您可以下载产生的捆绑软件,并使用OS X pkg实用工具( pkgbuildpkgutilproductbuild )对其进行修改,以包括您可能需要的其他内容。 例如,下面的脚本下载分布式分发包,向其添加用户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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM