-
-
Save b-long/f80a39e1f6e9804d2ab6 to your computer and use it in GitHub Desktop.
Bash function to detect if an R command uses an external connection of anykind. Designed to be used with R CMD check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Bash function to detect if an R command uses an external connection of | |
# any kind. Designed to be used with R CMD check | |
function has_external_connection { | |
DIR=$(mktemp -d) | |
# Use a local repository so we don't have to make an external connection for | |
# `available.packages()` | |
mkdir -p $DIR/src/contrib | |
wget -q -O $DIR/src/contrib/PACKAGES 'https://cran.rstudio.com/src/contrib/PACKAGES' | |
RPROFILE=$DIR/RProfile | |
echo "options(repos = c(CRAN='file://$DIR'))" > $RPROFILE | |
# Write trace results to outfile | |
OUTFILE=$(tempfile -d $DIR) | |
# Run the command using strace and trace only network system calls | |
strace -E R_PROFILE_USER=$RPROFILE -f -qq -o $OUTFILE -e trace=network "$@" | |
# Filter out | |
# 1. child process start and exit signals | |
# 2. local socket connections | |
# 3. Connection continuation lines | |
grep -q -E -v \ | |
-e "^[0-9]+ +[+-]{3}" \ | |
-e "[AP]F_LOCAL" \ | |
-e "^[0-9]+ +<\.\.\. connect resumed" \ | |
$OUTFILE | |
return $? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment