PageRenderTime 23ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/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
 1fb_maturity <- function(idFB = NA, Genus = NA, Species = NA, server = 'http://www.fishbase.tw/')
 2	{
 3require("XML")
 4require("stringr")
 5require('RCurl')
 6	if (is.na(idFB)) 
 7		{
 8		ids <- fb_ids(Genus=Genus, Species=Species, server= server)
 9		idFB <- ids$idFB
10		}
11  if ((is.na(idFB)) & (is.na(Genus) | is.na(Species)))
12    {
13    warning("idFB or Genus and Specie are required!")
14    }
15	if(!is.na(idFB))
16		{
17		url <- paste(server, "Reproduction/MaturityList.php?ID=", idFB, sep = "")
18		Mat <- readHTMLTable(url, as.data.frame=TRUE) ## I got the file as a XML class
19		if (is.null(Mat$dataTable))
20			{
21			Maturity <- c(as.character(idFB), as.character(Genus), as.character(Species), t(rep(NA, 11)))
22			names(Maturity) <- c('idFB', 'Genus', 'Species', 'lm', 'length_min', 'na1', 'length_max', 'Age_min', 'na2', 'Age_max', 'tm', 'Sex', 'Country', 'Locality')
23			Maturity <- t(Maturity)
24			}
25		if (!is.null(Mat$dataTable))
26			{
27			Maturity <- cbind(as.character(idFB), as.character(Genus), as.character(Species), Mat$dataTable)
28			names(Maturity) <- c('idFB', 'Genus', 'Species', 'lm', 'length_min', 'na1', 'length_max', 'Age_min', 'na2', 'Age_max', 'tm', 'Sex', 'Country', 'Locality')
29			}
30		}
31	return(as.data.frame(Maturity))
32	}