Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brandones/da0c8a81555b9873f1b275136a851401 to your computer and use it in GitHub Desktop.
Save brandones/da0c8a81555b9873f1b275136a851401 to your computer and use it in GitHub Desktop.
Appends Roxygen @Package docstring to README.md
#!/bin/bash
#
# Extracts the Roxygen package documentation from each script file in the
# package root directory and appends it to README.md
#
# Documentation that you want included should start on the second line of the script
OUTFILE="README.md"
r_files=( *.R )
echo >>${OUTFILE}
echo '## Script Documentation' >>${OUTFILE}
echo >>${OUTFILE}
for file in "${r_files[@]}"
do
echo '### '${file} >>${OUTFILE}
cat ${file} | \
grep "@docType package" -B100 | \
grep -v "@docType package" | \
sed "s/^.\{0,3\}//" | \
tail -n +2 \
>> ${OUTFILE}
echo >>${OUTFILE}
cat ${file} | \
grep "OUTPUT_PATH = " | \
sed "s/.*/- \`&\`/" \
>> ${OUTFILE}
echo >>${OUTFILE}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment