-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fb_tbl(spawnagg)? #284
Comments
@dannymooseLFC sorry but I don't follow your question. Perhaps you could provide a reproducible example of the code you are running? I really don't know what you mean by "an example" table. Calling For instance, I see this: fb_tbl("spawnagg")
# A tibble: 973 × 16
SpawnAggID C_Code SpecCode SynCode SpawnAggRef SpawningType AggregationType DirectSpawning IndirectSpawning CurrentStatus LunarPhase SpawningMonths HabitatType Management Gear Reference
<dbl> <chr> <int> <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 1 044 18 22722 NA Unknown Unknown "" High seasonal l… Unknown "" "" Other Spawning … Unkn… Carleton…
2 2 840 318 1918 NA Unknown Unknown "Spawning observation" High seasonal l… Gone "" "" Unspecified Time/area… Mid-… Bailey, …
3 3 192 154 22781 NA Unknown Unknown "Unspecified" High seasonal l… Decreasing "Full moo… "January, Feb… Outer reef… Unknown Unkn… Claro, R…
4 4 583 4460 25130 NA Unknown Transient "Unspecified" High seasonal l… Unknown "Full moo… "March, " Outer reef… Spawning … Unkn… Rhodes K…
5 5 583 6473 26142 NA Unknown Transient "Hydrated eggs" High seasonal l… Unknown "" "May, June, J… Outer reef… Unknown Hook… Rhodes K…
6 6 584 60479 5683 NA Unknown Resident "Spawning observation" Courtship; Colo… Unknown "" "November, " Reef chann… Unknown Unkn… Colin P.…
7 7 796 18 22722 NA Unknown Transient "Unspecified" Colour changes … Unknown "Full moo… "February, " Reef promo… Marine Pr… Trap Mark Tup…
8 8 084 1216 23652 NA Unknown Unknown "Unspecified" Colour changes … Unknown "First qu… "January, " Reef chann… Time/area… Hook… Salas E,…
9 9 084 12 22703 NA Unknown Unknown "Spawning observation; Hydrated egg… Courtship; High… Unknown "First qu… "" Reef chann… Spawning … Unkn… Salas E,…
10 10 192 18 22722 NA Unknown Unknown "Unspecified" High seasonal l… Unknown "" "" Other Unknown Unkn… Sadovy Y…
# ℹ 963 more rows
# ℹ Use `print(n = ...)` to see more rows |
@cboettig Apologies, I would say I'm still a beginner with R. I will try to explain my issue a bit more clearly. First of all, I set a value using the code Grouper <- species_list(Family = "Epinephelidae"). Which returns a chr of 170 species latin names. With this I get an error, as it says spawnagg does not exist as a function. I try the same code with "spawning" for example, and it works as intended. Does that make more sense? |
@dannymooseLFC thanks for clarifying, yes I follow now, though generally the best way to explain what you are doing is to literally paste the precise code you ran, what we call a reprex. I recommend a workflow like this: library(rfishbase)
library(dplyr)
## Get the whole spawning and spawn agg table, joined together:
spawn <- left_join(fb_tbl("spawning"), fb_tbl("spawnagg"), relationship = "many-to-many")
## Get the "taxa" table, a helper fn that combines Species tables with Family, Order, and Class tables.
taxa <- load_taxa()
# Filter taxa down to the desired species
groupers <- taxa |> filter(Family == "Epinephelidae")
## A "filtering join" (inner join)
spawn |> inner_join(groupers) Lemme know if the logic there is confusing. (Note the You tried the "old" syntax, which would look like: Grouper <- species_list(Family = "Epinephelidae")
Species_Spawning <- spawning(Grouper)
Species_Spawnagg <- spawnagg(Grouper) # ERROR!
left_join(Species_Spawning, Species_Spawnagg, relationship = "many-to-many") This doesn't ever use Note that both workflows are essentially the same 4 lines long. The new table-based approach uses more dplyr, and is more easily adapted. The main thing to know here is about using |
@cboettig The new syntax looks clearer so thank you for introducing me to it. Based on your penultimate paragraph, it appears that spawnagg is a table but not currently a function, is that correct? Meaning there isn't currently a way to produce a list of species with corresponding columns for "SpawningType", "AggregationType", "LunarPhase", "SpawningMonths" etc.? I can appreciate the huge amount of work that goes into these packages, so I only ask so it's clear for me, and not to judge! Many thanks |
Yes, but please note that there is no need for the functions like fb_tbl("spawnagg")
# A tibble: 973 × 16
SpawnAggID C_Code SpecCode SynCode SpawnAggRef SpawningType AggregationType DirectSpawning
<dbl> <chr> <int> <int> <int> <chr> <chr> <chr>
1 1 044 18 22722 NA Unknown Unknown ""
2 2 840 318 1918 NA Unknown Unknown "Spawning observation"
3 3 192 154 22781 NA Unknown Unknown "Unspecified"
4 4 583 4460 25130 NA Unknown Transient "Unspecified"
5 5 583 6473 26142 NA Unknown Transient "Hydrated eggs"
6 6 584 60479 5683 NA Unknown Resident "Spawning observation"
7 7 796 18 22722 NA Unknown Transient "Unspecified"
8 8 084 1216 23652 NA Unknown Unknown "Unspecified"
9 9 084 12 22703 NA Unknown Unknown "Spawning observation; Hydr…
10 10 192 18 22722 NA Unknown Unknown "Unspecified"
# ℹ 963 more rows
# ℹ 8 more variables: IndirectSpawning <chr>, CurrentStatus <chr>, LunarPhase <chr>, SpawningMonths <chr>,
# HabitatType <chr>, Management <chr>, Gear <chr>, Reference <chr>
# ℹ Use `print(n = ...)` to see more rows
> note that all those columns you mentioned are included. For all species. The code I showed above will combine this table with the spawning table and filter out those species not in the grouper family. Remember, everything is just a table now. You can filter it by whatever you want. You can join it to another table. Does this make sense? Thank you for your questions here! It helps me understand where we need to improve the README at very least! |
@cboettig Thank you :) Edit: If I only want the data from the spawnagg table and not the spawning table, what would the code look like for that? Thank you for answering my questions! |
To get only the fb_tbl("spawnagg") (likewise for any other table, e.g. |
The fb_table ("spawnagg") has the exact information I need for a list of grouper species. The table exists in the list, and gives me the example table when I use the code fb_tbl ("spawnagg"). However, when I use it in code alongside my species list it says that spawnagg doesn't exist as a function (only spawning appears as an option). Am I missing something here?
Any help appreciated :)
The text was updated successfully, but these errors were encountered: