cucumber flesh

Rを中心としたデータ分析・統計解析らへんの話題をしていくだけ

🍵MEEに掲載されたRパッケージのAdevent Calendarは実現可能なのか?

"Methods in Ecology and Evolution"(以下MEE)というジャーナルがあります。イギリス生態学会が刊行している生態学及び進化学系の学術誌で、ISIでの2014年の生態学分野におけるインパクトファクターの順位が9位(IF 6.554)であるそうです(すごい)。

この雑誌の中では、時々解析ツールとしてのRパッケージの紹介記事が掲載されます。他にも解析用のRパッケージを掲載する雑誌もありますが、こうしたパッケージを紹介する雑誌としてMEEがもっとも頻度が高い気がします。

12月といえばAdvent Calendarなわけですが、これに便乗して、「MEEで掲載されているRパッケージのまとめ」みたいなことをやったらあれこれ勉強になるような気がしたのですが、完走できるような気がしません。というかそもそも、ネタ的な意味で実現可能なのでしょうか。

というわけで12月に入る前に、MEEに掲載されたRパッケージ文献について調べてみました。

過去に刊行されている号から、{rvest}を使って判定基準となる論文のタイトルをスクレイピングしてきて、その中から以下の条件に合うものを抽出します(この条件以外にもRパッケージの記事があるかもしれませんが、今回はこういう条件ということで...)

  • "hoge: piyopiyo" という形式のタイトルであること(多くの記事がRパッケージ名: パッケージの概略、という形式であるため)
  • "R" をタイトルに含んでいること
# 必要なパッケージの読み込み
library(rvest)
library(pforeach)

まずは練習。最新号のタイトルを取得します。

scrape <- read_html("http://onlinelibrary.wiley.com/doi/10.1111/mee3.2014.5.issue-11/issuetoc")

titles <- scrape %>% html_nodes(xpath = "///ol/li/div/a") %>% html_text() %>% 
  grep("[[^*:]]*", ., value = TRUE) %>% 
  grep("[[:space:]]R[[:space:]]", ., value = TRUE, ignore.case = FALSE) %>% 
  gsub(" \\(.+?\\)", "", .)

titles
## [1] "ENMeval: An R package for conducting spatially independent evaluations and estimating optimal model complexity for Maxent ecological niche models"

こんな感じで抽出できました。

... というのを2010年の第1巻1号から2015年11月までに出版されている第6巻11号まで繰り返します。中途半端な関数を書いてみました。

base.url <- sprintf("http://onlinelibrary.wiley.com/doi/10.1111/mee3.%s.issue", 
                      paste(seq(2010, 2015), seq(1, 6), sep = "."))

get_title_in_r <- function(year = 1, iter = 2) {
  npforeach(i = 1:iter)({
    url <- paste0(base.url[[year]], "-%s", "/issuetoc") %>% sprintf(., i)
    message(url)
    read_html(url) %>% 
      html_nodes(xpath = "///ol/li/div/a") %>% 
      html_text() %>% 
      grep(pattern = "[[^*:]]*", x = ., value = TRUE) %>% 
      grep("[[:space:]]R[[:space:]]", ., value = TRUE, ignore.case = FALSE) %>% 
      gsub(" \\(.+?\\)", "", .)
})
}

res_2010 <- get_title_in_r(year = 1, iter = 4)
res_2011 <- get_title_in_r(year = 2, iter = 6)
res_2012 <- get_title_in_r(year = 3, iter = 6)
res_2013 <- get_title_in_r(year = 4, iter = 12)
res_2014 <- get_title_in_r(year = 5, iter = 12)
res_2015 <- get_title_in_r(year = 6, iter = 11)

res <- c(res_2010, res_2011, res_2012, 
         res_2013, res_2014, res_2015)
data.frame(Title = res) %>% knitr::kable(format = "markdown")
Title
RBrownie: an R package for testing hypotheses about rates of evolutionary change
phytools: an R package for phylogenetic comparative biology
BaSTA: an R package for Bayesian estimation of age-specific survival from incomplete mark–recapture/recovery data with covariates
abc: an R package for approximate Bayesian computation
RNETLOGO: an R package for running and exploring individual-based models implemented in NETLOGO
nadiv : an R package to create relatedness matrices for estimating non-additive genetic variances in animal models
popdemo: an R package for population demography using projection matrix analysis
paleotree: an R package for paleontological and phylogenetic analyses of evolution
betapart: an R package for the study of beta diversity
Treebase: an R package for discovery, access and manipulation of online phylogenies
FlexParamCurve: R package for flexible fitting of nonlinear parametric curves
Diversitree: comparative phylogenetic analyses of diversification in R
Cheddar: analysis and visualisation of ecological communities in R
IPMpack: an R package for integral projection models
nupoint: An R package for density estimation from point transects in the presence of nonuniform animal density
EasyABC: performing efficient approximate Bayesian computation sampling schemes using R
diveRsity: An R package for the estimation and exploration of population genetics parameters and their associated errors
marked: an R package for maximum likelihood and Markov Chain Monte Carlo analysis of capture–recapture data
pavo: an R package for the analysis, visualization and organization of spectral data
PASTIS: an R package to facilitate phylogenetic assembly with soft taxonomic inferences
PopGenReport: simplifying basic population genetic analyses in R
BAMMtools: an R package for the analysis of evolutionary dynamics on phylogenetic trees
Rphylip: an R interface for PHYLIP
mizer: an R package for multispecies, trait-based and community size spectrum ecological modelling
ENMeval: An R package for conducting spatially independent evaluations and estimating optimal model complexity for Maxent ecological niche models
TR8: an R package for easily retrieving plant species traits
StereoMorph: an R package for the collection of 3D landmarks and curves using a stereo camera set-up
LEA: An R package for landscape and ecological association studies
letsR: a new R package for data handling and analysis in macroecology

というわけで29件の文献が該当しました。クリスマスまでの25日... 無理ではなさそうですが、ちょっときつそうですね。さてどうしたものか。

2015-11-27 追記📝

せっかくなのでこれらのパッケージをインストールしておきます。上の表からスクレイピングしてきて、Rパッケージ名だけをベクターにします。

library(rvest)
# パッケージ名の取得
packages <- read_html("http://uribo.hatenablog.com/entry/2015/11/23/073000") %>% 
  html_table(fill = TRUE) %>% 
  data.frame() %>% 
  dplyr::mutate(Title = gsub(":.+", "", Title)) %$% 
  Title

# インストール可能なパッケージの一覧から、まだインストールされていないパッケージだけに絞る
packages %<>% .[!(. %in% installed.packages())]

# パッケージをインストールする
if (length(packages)) {
  install.packages(pkgs = packages, dependencies = TRUE)
}