#install.packages("remotes")
#remotes::install_github("ropensci/rfishbase")
library(rfishbase)
library(duckdb)
con <- dbConnect(duckdb::duckdb())
dbExecute(con, "INSTALL 'httpfs'")
dbExecute(con, "LOAD 'httpfs'")
#############
# 種名を指定
#species_name <- "Clupea harengus"
#species_name <- "Cyprinus carpio"
#species_name <- "Anguilla japonica"
#species_name <- "Gadus morhua"
# 種の情報を取得
species_info <- species(species_name)
# 生息環境を確認
habitat <- species_info$Fresh
if (habitat == "freshwater") {
cat(species_name, "は淡水魚です。\n")
} else if (habitat == "marine") {
cat(species_name, "は海水魚です。\n")
} else {
cat(species_name, "は淡水魚と海水魚の両方に生息します。\n")
}
# 科名を指定
family_name <- "Anguillidae"
# 科に属する種の情報を取得
species_list <- species(Family = family_name)
# 各種の生息環境を取得
habitats <- species_list %>%
rowwise() %>%
mutate(habitat = species(Species)$Fresh)
# 生息環境の集計
habitat_summary <- habitats %>%
group_by(habitat) %>%
summarise(count = n())
print(habitat_summary)