Making custom areacell, outdated vignette and division not showing in the database
Closed this issue · 1 comments
MikkoVihtakari commented
I noticed that the Vignette regarding areacell definition is outdated and does not work. The area
column in the dataframe should be called name
. I am using the GitHub version (6.2.99).
Also the division does not seem to be stored in the schema (tbl(mdb$db,"areacell")
)
library(mfdb)
library(tidyverse)
mfdb("test", destroy_schema = TRUE) # Delete 'test' in database for a fresh start
#> 2021-03-15 14:28:19 INFO:mfdb:Schema test removed, connect again to repopulate DB.
mdb <- mfdb("test")
#> 2021-03-15 14:28:20 INFO:mfdb:No schema, creating test
#> 2021-03-15 14:28:20 INFO:mfdb:Creating schema from scratch
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy case_study needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy institute needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy gear needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy vessel_type needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy market_category no updates to make
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy sex needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy maturity_stage needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy species needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy stomach_state needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy digestion_stage needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy index_type needs updating
#> 2021-03-15 14:28:20 INFO:mfdb:Creating indexes
# Out-of-date example:
mfdb_import_area(mdb,
data.frame(area = c('101', '102', '103', '401','402', '403'),
division = c('1', '1', '1', '4', '4', '4')))
#> Error in sanitise_col(mdb, data_in, "name"): Input data is missing 'name'. Columns available: area,division
dt <- data.frame(name = c('101', '102', '103', '401','402', '403')
division = c('1', '1', '1', '4', '4', '4'))
mfdb_import_area(mdb, dt)
#> 2021-03-15 14:28:20 INFO:mfdb:Taxonomy areacell needs updating
tbl(mdb$db,"areacell") %>% collect() # No division
#> # A tibble: 6 x 4
#> areacell_id name t_group size
#> <int> <chr> <chr> <dbl>
#> 1 1 101 <NA> NA
#> 2 2 102 <NA> NA
#> 3 3 103 <NA> NA
#> 4 4 401 <NA> NA
#> 5 5 402 <NA> NA
#> 6 6 403 <NA> NA
mfdb_import_division(mdb, dt %>% split(.$division) %>% map('name'))
tbl(mdb$db,"areacell") %>% collect() # Stil nothing
#> # A tibble: 6 x 4
#> areacell_id name t_group size
#> <int> <chr> <chr> <dbl>
#> 1 1 101 <NA> NA
#> 2 2 102 <NA> NA
#> 3 3 103 <NA> NA
#> 4 4 401 <NA> NA
#> 5 5 402 <NA> NA
#> 6 6 403 <NA> NA
Created on 2021-03-15 by the reprex package (v1.0.0)
bthe commented
Yes, sorry about that. I've edited the gadget-course notes so hopefully they are correct now. I haven't yet included an actual mfdb db when building the course which would have made spotting errors like this a lot easier.