Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RCurl or XML Challenge: Read Pastebin into R

Tags:

r

Flex your RCurl/XML muscle. Shortest code wins. Parse into R: http://pastebin.com/CDzYXNbG

Data should be:

structure(list(Treatment = structure(c(2L, 2L, 1L, 1L), .Label = c("C", 
"T"), class = "factor"), Gender = c("M", "F", "M", "F"), Response = c(56L, 
58L, 6L, 63L)), .Names = c("Treatment", "Gender", "Response"), row.names = c(NA, 
-4L), class = "data.frame")

Good luck!

Note: dummy data kindly provided by this question: Adding space between bars in ggplot2

like image 675
Brandon Bertelsen Avatar asked May 22 '11 07:05

Brandon Bertelsen


2 Answers

You guys are making this way too hard:

eval(parse(file("http://pastebin.com/raw.php?i=CDzYXNbG")))

OK, so I cheated. But starting from the same URL you could get the same end:

eval(parse(file(paste("http://pastebin.com/raw.php?i=", strsplit("http://pastebin.com/CDzYXNbG", "/")[[1]][4], sep=""))))

Which still puts me in the lead :)

like image 32
JD Long Avatar answered Sep 28 '22 18:09

JD Long


Same idea as kohske but slightly shorter and more clear I think

library(XML)
eval(parse(text=gsub('\r\n','\n',xpathApply(htmlTreeParse('http://pastebin.com/CDzYXNbG',useInternal=T),'//textarea',xmlValue))))
like image 150
cameron.bracken Avatar answered Sep 28 '22 17:09

cameron.bracken