--- /Library/Frameworks/R.framework/Resources/bin/R	2011-10-31 16:59:01.000000000 -0400
+++ /tmp/R.framework/Resources/bin/R	2011-11-05 16:11:23.000000000 -0400
@@ -1,30 +1,26 @@
 #!/bin/sh
 # Shell wrapper for R executable.
 
-R_HOME_DIR=/Library/Frameworks/R.framework/Resources
-if test "${R_HOME_DIR}" = "/Library/Frameworks/lib/R"; then
-   case "darwin9.8.0" in
-   linux*)
-     run_arch=`uname -m`
-     case "$run_arch" in 
-        x86_64|mips64|ppc64|powerpc64|sparc64|s390x)
-          libnn=lib64
-          libnn_fallback=lib
-        ;;
-        *)
-          libnn=lib
-          libnn_fallback=lib64
-        ;;
-     esac
-     if [ -x "/Library/Frameworks/${libnn}/R/bin/exec/R" ]; then
-        R_HOME_DIR="/Library/Frameworks/${libnn}/R"
-     elif [ -x "/Library/Frameworks/${libnn_fallback}/R/bin/exec/R" ]; then
-        R_HOME_DIR="/Library/Frameworks/${libnn_fallback}/R"
-     ## else -- leave alone (might be a sub-arch)
-     fi
-     ;;
+## find R_HOME from the script's directory
+PWD=`pwd`
+scriptdir=`dirname "$0"`
+case "$scriptdir" in
+    /*) ;;
+    *) scriptdir="$PWD/$scriptdir"
+esac
+
+# if the script is a symlink, we need to find the real source
+rslt="$0"
+while readlink "$rslt" >/dev/null; do
+  rslt=`readlink "$rslt"`
+  case "$rslt" in 
+      /*) ;;
+      *) rslt="$scriptdir/$rslt"
   esac
-fi
+  scriptdir=`dirname "$rslt"`
+done
+
+R_HOME_DIR=`cd "$scriptdir/.."; pwd; cd "$PWD"`
 
 if test -n "${R_HOME}" && \
    test "${R_HOME}" != "${R_HOME_DIR}"; then
@@ -32,18 +28,18 @@
 fi
 R_HOME="${R_HOME_DIR}"
 export R_HOME
-R_SHARE_DIR=/Library/Frameworks/R.framework/Resources/share
+R_SHARE_DIR="${R_HOME}/share"
 export R_SHARE_DIR
-R_INCLUDE_DIR=/Library/Frameworks/R.framework/Resources/include
+R_INCLUDE_DIR="${R_HOME}/include"
 export R_INCLUDE_DIR
-R_DOC_DIR=/Library/Frameworks/R.framework/Resources/doc
+R_DOC_DIR="${R_HOME}/doc"
 export R_DOC_DIR
 
 # Since this script can be called recursively, we allow R_ARCH to
 # be overridden from the environment.
 # This script is shared by parallel installs, so nothing in it should
 # depend on the sub-architecture except the default here.
-: ${R_ARCH=/`arch`}
+: ${R_ARCH=/`${R_HOME}/bin/arch`}
 
 usage="
 Usage: R [options] [< infile] [> outfile]