Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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