Permalink
Browse files

scripts for edits to notebook

  • Loading branch information...
cboettig committed Jan 17, 2013
1 parent 9250398 commit f86d80ff896b6973fb634163116dae639a406602
Showing with 75 additions and 46 deletions.
  1. +9 −0 fix-titles.sh
  2. +21 −0 get-uris.R
  3. +6 −0 tst.awk
  4. +39 −46 wordpress.md
View
@@ -0,0 +1,9 @@
+#! /bin/bash
+
+for f in *OWW*
+ #$(find . -iname "*md")
+ do
+ awk -f tst.awk $f > `basename $f .markdown`.md
+ mv `basename $f .markdown`.md $f
+done
+
View
@@ -0,0 +1,21 @@
+
+files <- system("ls *.markdown", intern=TRUE)
+
+require(knitr)
+require(gsubfn)
+
+
+makeuri <- function(url){
+ download.file(url, destfile="temp.png")
+ uri <- image_uri("temp.png")
+ system("rm temp.png")
+ paste("![](", uri, ")", sep="")
+}
+
+lapply(files,
+ function(file){
+ content <- readLines(file)
+ content <- gsubfn("!\\[.*\\]\\((http:.*[.png|.jpg])\\)", makeuri, content)
+ writeLines(content, file)
+ })
+
View
@@ -0,0 +1,6 @@
+(state == 0) && /^---$/ { state=1; print; next }
+(state == 1) && /^---$/ { state=2; next }
+(state == 2) && /^./ { state=3; printf "title: %s\n---\n",$0; next }
+(state == 3) && /^-+$/ { state=4; next }
+
+state != 2 { print }
View
@@ -7,82 +7,75 @@ I will base the wordpress format on the github-flavored markdown format. I chan
-
-[code lang='r']
+```r
render_gfm()
+options(width = 30)
opts_knit$set(upload = TRUE)
-knit_hooks$set(output = function(x,
- options) paste("[code]\n",
- x, "[/code]\n", sep = ""),
- source = function(x,
- options) paste("[code lang='r']\n",
- x, "[/code]\n",
- sep = ""), plot = hook_plot_html)
-[/code]
-
+knit_hooks$set(output = function(x, options) paste("[code]\n", x,
+ "[/code]\n", sep = ""), source = function(x, options) paste("[code lang='r']\n",
+ x, "[/code]\n", sep = ""), plot = hook_plot_html)
+```
Now we write some code chunks in this markdown file:
-[code lang='r']
-## a simple
-# calculator
+
+```r
+## a simple calculator
1 + 1
-[/code]
-[code]
+```
+
+```
## [1] 2
-[/code]
-[code lang='r']
-## boring random
-# numbers
+```
+
+```r
+## boring random numbers
set.seed(123)
rnorm(5)
-[/code]
-[code]
-## [1] -0.56048 -0.23018 1.55871
-## [4] 0.07051 0.12929
-[/code]
+```
+```
+## [1] -0.56048 -0.23018 1.55871 0.07051 0.12929
+```
We can also produce plots which are uploaded to imgur.com:
-[code lang='r']
+
+```r
library(ggplot2)
-qplot(hp, mpg,
- data = mtcars) + geom_smooth()
-[/code]
-<img src="http://i.imgur.com/YfwwX.png" class="plot" />
-[code lang='r']
-ggpcp(mtcars) +
- geom_line()
-[/code]
-<img src="http://i.imgur.com/udkrA.png" class="plot" />
+qplot(hp, mpg, data = mtcars) + geom_smooth()
+```
+
+![plot of chunk md-cars](ex-out-md-cars1.png)
+
+```r
+ggpcp(mtcars) + geom_line()
+```
+![plot of chunk md-cars](ex-out-md-cars2.png)
We can then post the result using RWordPress:
-[code lang='r']
+
+```r
require(RWordPress)
-text = paste(readLines("wordpress.md"),
- collapse = "\n")
+text = paste(readLines("wordpress.md"), collapse = "\n")
title = "Using knitr and RWordPress to publish results directly from R"
-newPost(list(description = text,
- title = title), publish = FALSE)
-[/code]
-
+newPost(list(description = text, title = title), publish = FALSE)
+```
Above we specify publish = FALSE which will make the post upload as a draft where we can preview it. To publish directly we could omit that command. Giving a title is intuitive. Note that we have to read the text in and substitue newline characters for line-breaks.
Note that this requires setting the login options securely in .Rprofile, for example:
-[code lang='r']
-options(WordpressLogin = c(userid = "password"),
- WordpressURL = "http://www.yourdomain.com/xmlrpc.php")
-[/code]
+```r
+options(WordpressLogin = c(userid = "password"), WordpressURL = "http://www.yourdomain.com/xmlrpc.php")
+```

0 comments on commit f86d80f

Please sign in to comment.