[R-SIG-Mac] Generating R .pkg file for Mac Distribution

Nigel Delaney nigelfdel@ney @ending from gm@il@com
Thu May 24 09:14:27 CEST 2018


James,

Thank you for the wonderful response and for making your packaging code
available (and producing this!).  Very much appreciated.

I wound up taking an approach where I just modified the CRAN R installer to
include a few more packages (specifically all I had installed).  I couldn't
find advice about this on the internet, so am attaching a subset of the
script I used below in case a future individual also wants some advice on
this.

Cheers,
Nigel


# Script to modify the R bundle to add more packages from the users library

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)

	[[alternative HTML version deleted]]



More information about the R-SIG-Mac mailing list