haotu : an open lab notebook

2014/02/14

scrape html table R

Filed under: Manipulate Data in R, R — Tags: , , , — S @ 03:25

 

library(XML)
theurl <- "http://en.wikipedia.org/wiki/Brazil_national_football_team"
tables <- readHTMLTable(theurl)
n.rows <- unlist(lapply(tables, function(t) dim(t)[1]))

the picked table is the longest one on the page

tables[[which.max(n.rows)]]


2014/02/07

Windows Zoom

Filed under: Windows 7 — Tags: , , , , , — S @ 03:30

Need to see something up close in Windows.

CTRL+middle mouse wheel

2014/02/05

R ls() search

Filed under: R — Tags: , , , — S @ 02:31
ls(pattern="tree")

From

x <- 1:10
f <- function() ls()
g <- function() ls(envir=.GlobalEnv)
h <- function() ls(envir=.GlobalEnv, pattern="[fg]")
f()
# character(0)
g()
# [1] "f" "g" "h" "x"
h()
# [1] "f" "g"

http://stackoverflow.com/questions/8142941/how-to-search-an-environment-using-ls-inside-a-function

2014/02/03

RStan install windows

Filed under: Bayesian, R — S @ 05:20

1. Rtools

https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows

2. Test. Make sure to run R as an administrator.

# using library inline to compile a C++ code on the fly
library(inline) 
library(Rcpp)
src <- ' 
  std::vector<std::string> s; 
  s.push_back("hello");
  s.push_back("world");
  return Rcpp::wrap(s);
'
hellofun <- cxxfunction(body = src, includes = '', plugin = 'Rcpp', verbose = FALSE)
cat(hellofun(), '\n')

3. Uninstall old versions

https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started

4. Install RStan

options(repos = c(getOption("repos"), rstan = "http://wiki.rstan-repo.googlecode.com/git/"))
install.packages('rstan', type = 'source')

5. Find the Makevars file in the .R folder in your Home directory

Edit in Notepad by deleting

-g

and changing

CXXFLAGS = -O3

oh3
Save it, but note that

set_cppo('debug')

will change it back and you will get an error. You will either need to edit the Makevars as above or run it in fast mode

set_cppo('fast')

If you have probs, look here

https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
https://github.com/stan-dev/rstan/issues

Blog at WordPress.com.