/R/fb_maturity.R
http://fb-scraping-project.googlecode.com/ · R · 32 lines · 32 code · 0 blank · 0 comment · 5 complexity · ae3f5032606811f284ce12c5befe7834 MD5 · raw file
- fb_maturity <- function(idFB = NA, Genus = NA, Species = NA, server = 'http://www.fishbase.tw/')
- {
- require("XML")
- require("stringr")
- require('RCurl')
- if (is.na(idFB))
- {
- ids <- fb_ids(Genus=Genus, Species=Species, server= server)
- idFB <- ids$idFB
- }
- if ((is.na(idFB)) & (is.na(Genus) | is.na(Species)))
- {
- warning("idFB or Genus and Specie are required!")
- }
- if(!is.na(idFB))
- {
- url <- paste(server, "Reproduction/MaturityList.php?ID=", idFB, sep = "")
- Mat <- readHTMLTable(url, as.data.frame=TRUE) ## I got the file as a XML class
- if (is.null(Mat$dataTable))
- {
- Maturity <- c(as.character(idFB), as.character(Genus), as.character(Species), t(rep(NA, 11)))
- names(Maturity) <- c('idFB', 'Genus', 'Species', 'lm', 'length_min', 'na1', 'length_max', 'Age_min', 'na2', 'Age_max', 'tm', 'Sex', 'Country', 'Locality')
- Maturity <- t(Maturity)
- }
- if (!is.null(Mat$dataTable))
- {
- Maturity <- cbind(as.character(idFB), as.character(Genus), as.character(Species), Mat$dataTable)
- names(Maturity) <- c('idFB', 'Genus', 'Species', 'lm', 'length_min', 'na1', 'length_max', 'Age_min', 'na2', 'Age_max', 'tm', 'Sex', 'Country', 'Locality')
- }
- }
- return(as.data.frame(Maturity))
- }