Skip to content

Instantly share code, notes, and snippets.

@yulijia
Last active June 8, 2017 03:24
Show Gist options
  • Save yulijia/6c9ea9d725b8022a32c4c776f8676acd to your computer and use it in GitHub Desktop.
Save yulijia/6c9ea9d725b8022a32c4c776f8676acd to your computer and use it in GitHub Desktop.
move animation inst example to website yihui.name/animation
#!/bin/bash
for i in /Users/lijia/yihui/content/animation/example/*.Rmd
do
bn=`basename $i`
cat $i | sed '/^slug:/s/\./-/' > $bn
done
#!/bin/bash
animation=/Users/lijia/animation/inst/examples/*.R
R=/Users/lijia/animation/R
out=/Users/lijia/yihui/content/animation/example
for i in $animation
do
bn=`basename $i -ex.R`
bm=`echo $bn | sed 's/\./-/g'`
echo $bm
#echo $bn
#touch $out/$bm.Rmd
echo "---" > $out/$bm.Rmd
echo "title: $bn()" >> $out/$bm.Rmd
#echo $i
title=`cat $i | grep title | grep -o -E "'.*'|\".*\"" | sed "s/'//g"`
if [[ $title != "" ]] ;then
echo "subtitle: $title" >> $out/$bm.Rmd
fi
echo "date: '2017-04-04'" >> $out/$bm.Rmd
# echo "slug: $bn" >> $out/$bm.Rmd
echo "slug: $bn" | sed 's/\./-/g' >> $out/$bm.Rmd
echo "---" >> $out/$bm.Rmd
cat $R/$bn.R | grep "#\'" | sed "/#' @/q" | grep -v "#\' @" | sed "s/#' //g" | sed "s/#'//g" | sed -e 's/\\command{\([^}]*\)}/`\1`/g' | sed -e 's/\\link{\([^}]*\)}/\1/g' | sed -e 's/\\code{\([^}]*\)}/`\1`/g' | sed -e 's/\\eqn{\([^}]*\)}/\$\1\$/g' | sed -e 's/\\item{\([^}]*\)}{\([^}]*\)}/- \1: \2\
/g' >> $out/$bm.Rmd
echo " " >> $out/$bm.Rmd
echo "\`\`\`{r demo-a, cache=TRUE, interval=.1}" >> $out/$bm.Rmd
echo "library(animation)" >> $out/$bm.Rmd
cat $i | sed -e 's/ani.options(oopt)//g' | sed 's/ifelse(interactive(), \([^]]*\), \([^]]*\))/\1)/g' | sed 's/oopt = //g'>> $out/$bm.Rmd
echo "\`\`\`" >> $out/$bm.Rmd
done
#!/bin/bash
for i in ./animation/R/*.R
do
bn=`basename $i .R | sed "s/\./-/g" | awk '{print tolower($0)}'`
if curl --output /dev/null --silent --head --fail "https://yihui.name/animation/example/$bn/"; then
sed -i "/#' @author Yihui Xie/a #' @references Examples at \\\url{https://yihui.name/animation/example/$bn/}" $i
else
echo $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment