spark-instrumented-optimizer/R/create-rd.sh

38 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This scripts packages the SparkR source files (R and C files) and
# creates a package that can be loaded in R. The package is by default installed to
# $FWDIR/lib and the package can be loaded by using the following command in R:
#
# library(SparkR, lib.loc="$FWDIR/lib")
#
# NOTE(shivaram): Right now we use $SPARK_HOME/R/lib to be the installation directory
# to load the SparkR package on the worker nodes.
set -o pipefail
set -e
FWDIR="$(cd "`dirname "${BASH_SOURCE[0]}"`"; pwd)"
pushd "$FWDIR" > /dev/null
. "$FWDIR/find-r.sh"
# Generate Rd files if devtools is installed
[SPARK-31510][R][BUILD] Set setwd in R documentation build Seems like in certain environment, it requires to set `setwd` as below: ``` > library(devtools); devtools::document(pkg="./pkg", roclets=c("rd")) Loading required package: usethis Error: Could not find package root, is your working directory inside a package? ``` see also https://stackoverflow.com/questions/52670051/how-to-troubleshoot-error-could-not-find-package-root and https://groups.google.com/forum/#!topic/rdevtools/79jjjdc_wjg We can make up another story too. For example, if you set a specific directory in your `~/.Rprofile`, then R documentation build will fail as below: ``` echo 'setwd("~")' > ~/.Rprofile sh R/create-rd.sh ``` ``` Using R_SCRIPT_PATH = /usr/local/bin Loading required package: usethis Error: Can't find './pkg'. Execution halted ``` This PR proposes to set the `setwd` explicitly so it does not get affected on the global environment. To make R dev env more independent. No, dev only. Manually tested: ```bash echo 'setwd("~")' > ~/.Rprofile sh R/create-rd.sh ``` Before: ``` Using R_SCRIPT_PATH = /usr/local/bin Loading required package: usethis Error: Can't find './pkg'. Execution halted ``` After: ``` Using R_SCRIPT_PATH = /usr/local/bin Loading required package: usethis Updating SparkR documentation Loading SparkR Creating a new generic function for ‘as.data.frame’ in package ‘SparkR’ Creating a new generic function for ‘colnames’ in package ‘SparkR’ Creating a new generic function for ‘colnames<-’ in package ‘SparkR’ Creating a new generic function for ‘cov’ in package ‘SparkR’ Creating a new generic function for ‘drop’ in package ‘SparkR’ Creating a new generic function for ‘na.omit’ in package ‘SparkR’ Creating a new generic function for ‘filter’ in package ‘SparkR’ Creating a new generic function for ‘intersect’ in package ‘SparkR’ ... ``` Closes #28285
2020-04-21 11:38:57 -04:00
"$R_SCRIPT_PATH/Rscript" -e ' if("devtools" %in% rownames(installed.packages())) { library(devtools); setwd("'$FWDIR'"); devtools::document(pkg="./pkg", roclets=c("rd")) }'