Commit 9fb40a76 authored by Holger Brandl's avatar Holger Brandl

added `mutate_inplace`

parent cff7b65c
......@@ -411,6 +411,21 @@ first_group = function(groupedDF){
}
mutate_inplace <- function(data, var, expr){
install_package("rlang")
var <- enexpr(var)
var_name <- quo_name(var)
expr <- enexpr(expr)
call <- quo(UQ(var) %>% UQ(expr))
print(call)
mutate(data, !!var_name := UQ(call))
}
# mutate_inplace( iris, Species, str_replace("vir", "foo") )
reload_dplyr <- function(){
unloadNamespace('tidyr')
......
Files in the directory should not be used any longer. Use ../spinr instead
\ No newline at end of file
## a thin wrapper around spin to make it more useful with more custom output
require(plyr)
require(knitr)
require(stringr)
options(width=150)
#https://groups.google.com/forum/#!topic/knitr/ojcnq5Nm298
## better table css: http://www.stat.ubc.ca/~jenny/STAT545A/topic10_tablesCSS.html
spin(rScript, knit=F)
mdScript <- str_replace(rScript, "[.]R$", ".Rmd")
system(paste("mv", mdScript, "tmp.Rmd"))
system(paste("cat tmp.Rmd | grep -Ev '^#+$' | grep -Fv '#!/usr/bin/env Rscript' >", basename(mdScript)))
file.remove("tmp.Rmd")
cssHeader='
<style type="text/css">
body {
max-width: 90%;
}
</style>
'
## custom title http://stackoverflow.com/questions/14124022/setting-html-meta-elements-with-knitr
opts_chunk$set(cache = TRUE, fig.width=10, width=120)
knit2html(basename(mdScript), header=cssHeader)
file.remove(basename(mdScript))
spinr(){
if [ $# -lt 1 ]; then
echo -e "Usage: spinr <script.R> [<other args>*]\nJust knit R documents as they are, no markdown is required (but supported to some extent)"
return
fi
rscript=$1
if [ ! -f $rscript ]; then
>&2 echo "$rscript does not exist"; exit;
fi
## rscript=/Users/brandl/Dropbox/Public/datautils/R/rknit/rknit_example.R
# echo 'devtools::source_url("https://dl.dropboxusercontent.com/u/113630701/datautils/R/utils/spinr.R"); spinr("'$rscript'")' | R --vanilla -q
echo 'rScript="'$rscript'"; devtools::source_url("https://dl.dropboxusercontent.com/u/113630701/datautils/R/utils/spinr.R")' | R --vanilla -q --args $*
rm *md
}
spinsnip(){
if [ $# -ne 1 ]; then
>&2 echo "Usage: spinsnip <report name>"
return
fi
reportName=$1
tmpR=$(echo $reportName | tr " " "_").R
## http://stackoverflow.com/questions/11454343/pipe-output-to-bash-function
cat | sed 's/#>/#'"'"'/g' > $tmpR
echo "spining $tmpR..."
spinr $tmpR
rm $tmpR
}
#testsnip(){
# cat > test.txt
#}
#' cd /home/brandl/mnt/mack/project-raphael/reports/spin_report
#' source <(curl https://dl.dropboxusercontent.com/u/113630701/datautils/R/utils/spinr.sh)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment