简体   繁体   中英

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

CRAN allows Mac users to install R with a .pkg file for download here:

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

Presumably this is generated by running pkgbuild on a compiled version of R. Does anyone know where the source script for this process is located? Or how the process could be pseudo-replicated?

The source for the commands that make the R bundle is not available. However, you can download the produced bundle, and use the OS X pkg utilities ( pkgbuild , pkgutil , productbuild ) to modify it to include other things you might need. For example, the script below downloads the distributed bundle, adds any packages in the users R library to it, then rebundles it for distribution.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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