| Title: | An R Package for Extraction of AFSC Fishery Data |
|---|---|
| Description: | This package provides a folder structure and SQL queries for accessing the AKFIN and AFSC databases in support of fishery stock assessments. Additionally, archived data are held/provided to maintain consistency across assessments/assessment authors. |
| Authors: | Benjamin Williams [aut, cre], Jane Sullivan [ctb], Steve Barbeaux [ctb], Pete Hulson [ctb], Jim Ianelli [ctb], Matt Callahan [ctb], Meaghan Bryan [ctb], Kalei Shotwell [ctb], Margaret Siple [ctb] |
| Maintainer: | The package maintainer <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-05-24 10:17:07 UTC |
| Source: | https://github.com/afsc-assessments/afscdata |
copy of all base model files, adds a "README.md" file that identifies the model used (or appends the current README), predicated on using the 'afscdata::setup_folders()' function, though has an option for other folder structures. Note, this function copies everything over (e.g., retrospectives) and may take a few minutes to complete
accepted_model(base_year, base_model, year, folder = NULL)accepted_model(base_year, base_model, year, folder = NULL)
base_year |
year of the base model |
base_model |
name of the base model (folder name) |
year |
current year |
folder |
if the base model is in a different location than the afscdata structure is looking for |
a 'base' model folder with all of the prior years inputs/outputs
## Not run: accepted_model(base_year = 2020, base_model = "m18.2b", year = 2021) ## End(Not run)## Not run: accepted_model(base_year = 2020, base_model = "m18.2b", year = 2021) ## End(Not run)
raw data query for the BSAI Atka mackerel assessment
bsai_amak(year, off_yr = FALSE)bsai_amak(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: bsai_amak(year = 2023, off_yr = TRUE) ## End(Not run)## Not run: bsai_amak(year = 2023, off_yr = TRUE) ## End(Not run)
A dataset containing historical catch data by year for 1977-1990, pulled from 2022 stock assessment data file.
bsai_amak_catch_1977_1990bsai_amak_catch_1977_1990
A data frame with 14 observations and 2 variables:
1977-1990
catch in tons
raw data query for BSAI arrowtooth flounder
bsai_atf(year, off_yr = FALSE)bsai_atf(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: bsai_atf(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: bsai_atf(year = 2022, off_yr = FALSE) ## End(Not run)
raw data query for BSAI flathead sole
bsai_fhs(year, off_yr = FALSE)bsai_fhs(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: bsai_fhs(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: bsai_fhs(year = 2022, off_yr = FALSE) ## End(Not run)
A dataset containing trawl gear catch by year for 1964-1994
bsai_fhs_catch_1964_1994bsai_fhs_catch_1964_1994
A data frame with 30 observations and 2 variables:
year of catch
weight of catch in 1,000 t
raw data query for BSAI northern rocksole
bsai_nrs(year, off_yr = FALSE)bsai_nrs(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: bsai_atf(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: bsai_atf(year = 2022, off_yr = FALSE) ## End(Not run)
raw data query for BSAI octopus
bsai_octopus(year)bsai_octopus(year)
year |
assessment year |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: bsai_octopus(year = 2023) ## End(Not run)## Not run: bsai_octopus(year = 2023) ## End(Not run)
raw data query for BSAI other rockfish
bsai_orox(year, off_yr = FALSE, catch_report = FALSE)bsai_orox(year, off_yr = FALSE, catch_report = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
catch_report |
is this a catch report year, default FALSE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: bsai_orox(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: bsai_orox(year = 2022, off_yr = FALSE) ## End(Not run)
Reformat Catch to SS3 structure currently only handles a single fleet, values in t
catch_to_ss3(year, se = 0.01, season = 7, fleet = 1, yld_rat = NULL)catch_to_ss3(year, se = 0.01, season = 7, fleet = 1, yld_rat = NULL)
year |
assessment year |
se |
standard error in log space, typically quite small |
season |
numeric month for catches to be applied |
fleet |
numeric id of the fishery fleet |
yld_rat |
default NULL; else look for a vector with the projected-in year catch in output/ and replace |
saves a csv in output/ with the correct format
adds correct quotes for sql queries, nested within sql_filter
collapse_filters(x)collapse_filters(x)
x |
variable to add quotes to |
utility function to connect to server
connect(db = "akfin")connect(db = "akfin")
db |
the database schema ("akfin" or "afsc") |
utility function to disconnect from server
disconnect(db)disconnect(db)
db |
the database schema (e.g., akfin or afsc) |
A dataset containing area definitions
fmp_keyfmp_key
A data frame with 923 observations and 2 variables:
long_lat
defined area for location
compare GAP updated survey biomass to (now) retired design-based biomass estimates
gap_check_bio(year, species, area, type)gap_check_bio(year, species, area, type)
year |
current year |
species |
afsc species codes e.g., 30420 |
area |
options = ai, goa, ebs, bss, nbs |
type |
= region, subarea, area, stat_area, stratum, inpfc, inpfc_depth, depth, reg_area_depth |
a list with orig values, gap values, and a basic report
## Not run: out <- gap_check_bio(year = 2024, species = 30420, type = 'total', area = 'AI' ) out$report ## End(Not run)## Not run: out <- gap_check_bio(year = 2024, species = 30420, type = 'total', area = 'AI' ) out$report ## End(Not run)
raw data query for the GOA Atka mackerel assessment
goa_amak(year)goa_amak(year)
year |
assessment year |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_amak(year = 2023) ## End(Not run)## Not run: goa_amak(year = 2023) ## End(Not run)
raw data query for GOA arrowtooth founder
goa_atf(year, off_yr = FALSE)goa_atf(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_atf(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: goa_atf(year = 2022, off_yr = FALSE) ## End(Not run)
A dataset containing trawl gear catch by year for 1961-1990
goa_atf_catch_1961_1990goa_atf_catch_1961_1990
A data frame with 30 observations and 2 variables:
year of catch
weight of catch in 1,000 t
raw data query for GOA dusky rockfish
goa_dusk(year, off_yr = FALSE)goa_dusk(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_dusk(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: goa_dusk(year = 2022, off_yr = FALSE) ## End(Not run)
A dataset containing trawl gear catch by year for 1977-1990
goa_dusk_catch_1977_1990goa_dusk_catch_1977_1990
A data frame with 14 observations and 2 variables:
year of catch
weight of catch in 1,000 t
raw data query for GOA flathead sole
goa_fhs(year, off_yr = FALSE)goa_fhs(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_fhs(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: goa_fhs(year = 2022, off_yr = FALSE) ## End(Not run)
A dataset containing historical catch data by year for 1978-1990
goa_fhs_catch_1978_1990goa_fhs_catch_1978_1990
A data frame with 13 observations and 2 variables:
1978-1990
catch in tons
raw data query for GOA northern rockfish
goa_nork(year, off_yr = FALSE)goa_nork(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_nork(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: goa_nork(year = 2022, off_yr = FALSE) ## End(Not run)
A dataset containing trawl gear catch by year for 1961-1992
goa_nork_catch_1961_1992goa_nork_catch_1961_1992
A data frame with 32 observations and 2 variables:
year of catch
weight of catch in 1,000 t
raw data query for GOA octopus
goa_octopus(year)goa_octopus(year)
year |
assessment year |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_octopus(year = 2023) ## End(Not run)## Not run: goa_octopus(year = 2023) ## End(Not run)
A dataset containing historical catch data by year for 1977-1990
goa_pcod_catch_1977_1990goa_pcod_catch_1977_1990
A data frame with 280 observations and 4 variables:
catch in tons
fishery gear type
1977-1990
quarterly fishery season
A dataset containing larval index collections year for 1977-2022
goa_pcod_larval_indicesgoa_pcod_larval_indices
A data frame with 92 observations and 5 variables:
1977-2022
season?
index id
observation
log standard error of obs
raw data query for GOA POP
goa_pop(year, off_yr = FALSE)goa_pop(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_pop(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: goa_pop(year = 2022, off_yr = FALSE) ## End(Not run)
A dataset containing trawl gear catch by year for 1961-1990
goa_pop_catch_1960_1990goa_pop_catch_1960_1990
A data frame with 30 observations and 2 variables:
year of catch
weight of catch in 1,000 t
A dataset containing length comp collection data by year for 1963-1977
goa_pop_fixed_fish_length_compgoa_pop_fixed_fish_length_comp
A data frame with 765 observations and 4 variables:
length in cm
number of lengths collected
1963-1977
number of hauls sampled
raw data query for GOA rougheye/blackspotted rockfish
goa_rebs(year, off_yr = FALSE)goa_rebs(year, off_yr = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_rebs(year = 2021, off_yr = FALSE) ## End(Not run)## Not run: goa_rebs(year = 2021, off_yr = FALSE) ## End(Not run)
A dataset containing trawl and longline gear catch by year for 1977-2004
goa_rebs_catch_1977_2004goa_rebs_catch_1977_2004
A data frame with 28 observations and 2 variables:
year of catch
weight of catch in t
The catches from 1977-1992 were from Soh (1998), which reconstructs the catch history using an information weighting factor (λ) to combine catch histories from both survey and fishery information. The catches from 1993-2004 were constructed used observer catch data from the FMA Observer Program (Clausen et al. 2004, Appendix A). Observed catches were available from the FMA database by area, gear, and species for hauls sampled by observers. This information was used to calculate proportions of RE/BS catch by gear type. These proportions were then applied to the combined shortraker/rougheye catch from the NMFS Alaska Regional Office to yield estimates of total catch for RE/BS rockfish.
Clausen, D. M., D.H. Hanselman, J.T. Fujioka, and J. Heifetz. 2004. Gulf of Alaska shortraker/rougheye and other slope rockfish. In Stock assessment and fishery evaluation report for the groundfish resources of the Gulf of Alaska, p. 413 – 463. North Pacific Fishery Management Council, 605 W 4th Ave, Suite 306, Anchorage AK 99501. https://apps-afsc.fisheries.noaa.gov/refm/docs/2004/GOAsloperf.pdf
Soh, Sung Kwon. 1998. The use of harvest refugia in the management of shortraker and rougheye rockfish (Sebastes borealis/Sebastes aleutianus) in the Gulf of Alaska. Ph.D. Thesis – University of Washington. 194 pp.
raw data query for GOA shallow-water flatfish
goa_shal_flats(year, off_yr = FALSE, catch_report = FALSE)goa_shal_flats(year, off_yr = FALSE, catch_report = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
catch_report |
is this a catch report year, default FALSE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_shal_flats(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: goa_shal_flats(year = 2022, off_yr = FALSE) ## End(Not run)
raw data query for GOA thorynhead rockfish
goa_thornyhead(year, off_yr = FALSE, catch_report = FALSE)goa_thornyhead(year, off_yr = FALSE, catch_report = FALSE)
year |
assessment year |
off_yr |
if this is an off-year assessment change to TRUE |
catch_report |
is this a catch report year, default FALSE |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: goa_thornyhead(year = 2022, off_yr = FALSE) ## End(Not run)## Not run: goa_thornyhead(year = 2022, off_yr = FALSE) ## End(Not run)
currently only available for goa and ai total age comps (not strata)
q_bts_agecomp(year, species, area, db, print_sql = FALSE, save = TRUE)q_bts_agecomp(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
5 digit afsc species code(s) e.g., 79210 or c(79210, 90210) |
area |
options are 'ai' or 'goa' - can only call a single area |
db |
the database to query (afsc) |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
save the file in designated folder, if FALSE outputs to global environment |
for the goa and ai there is a "type" switch that queries by stratum, or total - !!stratum should not be used at the moment !!. only one of these can be used at a time.
saves bts agecomp data as data/raw/area_bts_age_data.csv and area_bts_age_specimen_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect("afsc") q_bts_agecomp(year=2022, species=21921, area = "goa", db = db) ## End(Not run)## Not run: db <- afscdata::connect("afsc") q_bts_agecomp(year=2022, species=21921, area = "goa", db = db) ## End(Not run)
probably need to beef up the documentation on the "by" switch
q_bts_biomass( year, species, area, type = "total", db, print_sql = FALSE, save = TRUE )q_bts_biomass( year, species, area, type = "total", db, print_sql = FALSE, save = TRUE )
year |
max year to retrieve data from |
species |
5 digit afsc species code(s) e.g., 79210 or c(79210, 90210) |
area |
options are bs (the bs+nw), bsslope, nbs, ai, goa, old_bs (was called "standard") - can only call a single area |
type |
"depth", "stratum", "area", "total", "inpfc", "inpfc_depth" - only available for goa/ai (default: "total") - can only use a single switch |
db |
the database to query (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
save the file in designated folder, if FALSE outputs to global environment |
six areas are available to query from bs = bering sea + northwest 1987-present (includes nw stations) - recommended bsslope = bering sea slope nbs = northern bering sea ai = aleutian islands goa = gulf of alaska old_bs = bering sea standard 1982-present (minus ~20 stations in nw) - not recommended
for the goa and ai there is a "type" switch that queries by depth, stratum, area, total, or uses the inpfc table or inpfc by depth table only one of these can be used at a time.
saves bts biomass data as data/raw/area_(type)_bts_biomass_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect("akfin") q_bts_biomass(year=2022, species=21921, area = "goa", type = "depth", db = db) ## End(Not run)## Not run: db <- afscdata::connect("akfin") q_bts_biomass(year=2022, species=21921, area = "goa", type = "depth", db = db) ## End(Not run)
query GAP bottom trawl survey agecomps
q_bts_gap_agecomp(year, species, area, db, print_sql = FALSE, save = TRUE)q_bts_gap_agecomp(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
5 digit species code (e.g., 10110) - can place multiple in a vector c(10110, 10130) |
area |
options: ebs, ai, goa, nbs, ebs_slope, ebs_nbs, default: goa |
db |
data server to connect to (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: true) |
saves bts length data as data/raw/bts_gap_agecomp_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect() q_bts_gap_agecomp(year=2022, species=21921, area = "goa", db = db) ## End(Not run)## Not run: db <- afscdata::connect() q_bts_gap_agecomp(year=2022, species=21921, area = "goa", db = db) ## End(Not run)
query bottom trawl survey length data from GAP on the AKFIN server
q_bts_gap_length(year, species, area, db, print_sql = FALSE, save = TRUE)q_bts_gap_length(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
5 digit species code (e.g., 10110) - can place multiple in a vector c(10110, 10130) |
area |
ebs, nbs, ebs_slope, ebs_nbs, ai, goa - can do multiples c("bs","ai") |
db |
data server to connect to (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) - save must be false |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: true) |
saves bts length data as data/raw/bts_length_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect() q_bts_gap_length(year=2022, species=10110, area = "goa", db = db) ## End(Not run)## Not run: db <- afscdata::connect() q_bts_gap_length(year=2022, species=10110, area = "goa", db = db) ## End(Not run)
query GAP bottom trawl survey sizecomps
q_bts_gap_sizecomp(year, species, area, db, print_sql = FALSE, save = TRUE)q_bts_gap_sizecomp(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
5 digit afsc species code(s) e.g., 79210 or c(79210, 90210) |
area |
options: ebs, ai, goa, nbs, ebs_slope, ebs_nbs, default: goa |
db |
the database to query (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
save the file in designated folder, if FALSE outputs to global environment |
saves bts sizecomp data as data/raw/area_bts_gap_sizecomp_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect() q_bts_gap_sizecomp(year=2022, species=21921, area = "goa", db = db) ## End(Not run)## Not run: db <- afscdata::connect() q_bts_gap_sizecomp(year=2022, species=21921, area = "goa", db = db) ## End(Not run)
query GAP bottom trawl survey specimen data from the AKFIN server
q_bts_gap_specimen(year, species, area, db, print_sql = FALSE, save = TRUE)q_bts_gap_specimen(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
5 digit species code (e.g., 10110) - can place multiple in a vector c(10110, 10130) |
area |
options: ebs, ai, goa, nbs, ebs_slope, ebs_nbs, default: goa |
db |
data server to connect to (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: true) |
saves bts length data as data/raw/bts_length_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect() q_bts_gap_specimen(year=2022, species=21921, area = "goa", db = db) ## End(Not run)## Not run: db <- afscdata::connect() q_bts_gap_specimen(year=2022, species=21921, area = "goa", db = db) ## End(Not run)
query bottom trawl survey length data from the AFSC server
q_bts_length(year, species, area, db, print_sql = FALSE, save = TRUE)q_bts_length(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
5 digit species code (e.g., 10110) - can place multiple in a vector c(10110, 10130) |
area |
bs, ai, goa, or hwc, wc, hg, hbs - can do multiples c("bs","ai") |
db |
data server to connect to (afsc) |
print_sql |
outputs the sql query instead of calling the data (default: false) - save must be false |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: true) |
saves bts length data as data/raw/bts_length_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect("afsc") q_bts_length(year=2022, species=10110, area = "goa", db = db) ## End(Not run)## Not run: db <- afscdata::connect("afsc") q_bts_length(year=2022, species=10110, area = "goa", db = db) ## End(Not run)
currently only available for goa and ai total size comps
q_bts_sizecomp(year, species, area, db, print_sql = FALSE, save = TRUE)q_bts_sizecomp(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
5 digit afsc species code(s) e.g., 79210 or c(79210, 90210) |
area |
options are 'ai' or 'goa' - can only call a single area |
db |
the database to query (afsc) |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
save the file in designated folder, if FALSE outputs to global environment |
saves bts sizecomp data as data/raw/area_bts_sizecomp_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect("afsc") q_bts_sizecomp(year=2022, species=21921, area = "goa", db = db) ## End(Not run)## Not run: db <- afscdata::connect("afsc") q_bts_sizecomp(year=2022, species=21921, area = "goa", db = db) ## End(Not run)
query bottom trawl survey specimen data from the AFSC server
q_bts_specimen(year, species, area, db, print_sql = FALSE, save = TRUE)q_bts_specimen(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
5 digit species code (e.g., 10110) - can place multiple in a vector c(10110, 10130) |
area |
bs, ai, goa, or hwc, wc, hg, hbs - can do multiples c("bs","ai") |
db |
data server to connect to (afsc) |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: true) |
saves bts length data as data/raw/bts_length_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect("afsc") q_bts_length(year=2022, species=21921, area = "goa", db = db) ## End(Not run)## Not run: db <- afscdata::connect("afsc") q_bts_length(year=2022, species=21921, area = "goa", db = db) ## End(Not run)
Note that this function produces results that may be confidential. They can be hidden from git/GitHub by adding fish_catch_data.csv to your .gitignore file
q_catch( year, species, area, db, add_fields = NULL, print_sql = FALSE, save = TRUE )q_catch( year, species, area, db, add_fields = NULL, print_sql = FALSE, save = TRUE )
year |
max year to retrieve data from |
species |
species group code e.g., "DUSK" or numeric agency values e.g. c("131", "132") - must be either all 4 digit or 3 digit codes |
area |
fmp_area (GOA, BSAI) or fmp_subarea (BS, AI, WG, CG, WY, EY, SE) - also available (SEI, PWSI), can use all fmp_areas or all fmp_subareas, but don't mix the two |
db |
data server to connect to (akfin) |
add_fields |
add other columns to the database (must currently exist on server). "*" will return all table columns available |
print_sql |
outputs the sql query instead of calling the data - save must be false |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: TRUE) |
saves catch data as data/raw/fish_catch_data.csv or outputs to the global environment, save also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect() q_catch(year=2022, species="NORK", area="goa", db=db) ## End(Not run)## Not run: db <- afscdata::connect() q_catch(year=2022, species="NORK", area="goa", db=db) ## End(Not run)
something about the species names and area codes, since they are so different from everything else? pulls data from AKFIN pre1991.foreign_blend table
q_catch_foreign(year, species, area, db, print_sql = FALSE, save = TRUE)q_catch_foreign(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
common name (e.g., "sablefish" or "all flounders") - can call multiple species |
area |
numeric area digit code - multiples is ok |
db |
data server to connect to (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) - save must be false |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: true) |
saves catch data as data/raw/for_catch_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect() q_catch_foreign(year=2022, species="sablefish", area = 54:57, db = db) ## End(Not run)## Not run: db <- afscdata::connect() q_catch_foreign(year=2022, species="sablefish", area = 54:57, db = db) ## End(Not run)
utility function for date of data query
q_date(year, loc = NULL)q_date(year, loc = NULL)
year |
assessment year |
loc |
location to save file if different from default |
a query date file saved as year/data/raw/data_called.txt
currently setup for pulling haul level detail for age or length compositions
q_fish_obs(year, species, area, db, print_sql = FALSE, save = TRUE)q_fish_obs(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
max year to retrieve data from |
species |
numeric agency values e.g. c("131", "132") - must be 3 digit codes (norpac species codes) |
area |
fmp_area (GOA, BSAI) or fmp_subarea (BS, AI, WG, CG, WY, EY, SE) - also available (SEI, PWSI), can use all fmp_areas or all fmp_subareas, but don't mix the two |
db |
data server to connect to (akfin) |
print_sql |
outputs the sql query instead of calling the data - save must be false |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: TRUE) |
saves observer data as data/raw/fish_obs_data.csv or outputs to the global environment, save also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect() q_fish_obs(year=2022, species=301, area="goa", db=db) ## End(Not run)## Not run: db <- afscdata::connect() q_fish_obs(year=2022, species=301, area="goa", db=db) ## End(Not run)
query fish ticket data
q_fish_ticket( year, species, area, db, add_fields = NULL, print_sql = FALSE, save = TRUE )q_fish_ticket( year, species, area, db, add_fields = NULL, print_sql = FALSE, save = TRUE )
year |
max year to query through (and location to save results) |
species |
species group code e.g., "DUSK" |
area |
fmp_area (GOA, BSAI) or fmp_subarea (BS, AI, WG, CG, WY, EY, SE) - also available (SEI, PWSI), can use all fmp_areas or all fmp_subareas, but don't mix the two |
db |
data server to connect to (akfin) |
add_fields |
add other columns to the database (must currently exist on server). "*" will return all table columns available |
print_sql |
outputs the sql query instead of calling the data - save must be false |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: TRUE) |
saves fish ticket data as data/raw/fishticket_data.csv or outputs to the global environment, save also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: q_fish_ticket(year=2022, species="NORK", area="goa", db=db) ## End(Not run)## Not run: q_fish_ticket(year=2022, species="NORK", area="goa", db=db) ## End(Not run)
query fishery length data from the AKFIN server
q_fsh_length( year, species, area, db, add_fields = NULL, print_sql = FALSE, save = TRUE )q_fsh_length( year, species, area, db, add_fields = NULL, print_sql = FALSE, save = TRUE )
year |
max year to retrieve data from |
species |
3 digit species codes (e.g., 201) - can place multiple in a vector c(201, 131) |
area |
bs, ai, goa, or hwc, wc, hg, hbs - can do multiples c("bs","ai") |
db |
data server to connect to (akfin) |
add_fields |
add other columns to the database (must currently exist on server). "*" will return all table columns available |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: true) |
saves fishery length data as data/raw/fish_length_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect("akfin") q_fsh_length(year=2022, species=301, area="goa", db=db) ## End(Not run)## Not run: db <- afscdata::connect("akfin") q_fsh_length(year=2022, species=301, area="goa", db=db) ## End(Not run)
query fishery specimen data from the AKFIN server
q_fsh_specimen( year, species, area, db, add_fields = NULL, print_sql = FALSE, save = TRUE )q_fsh_specimen( year, species, area, db, add_fields = NULL, print_sql = FALSE, save = TRUE )
year |
max year to retrieve data from |
species |
3 digit species codes (e.g., 201) - can place multiple in a vector c(201, 131) |
area |
bs, ai, goa, or hwc, wc, hg, hbs - can do multiples c("bs","ai") |
db |
data server to connect to (akfin) |
add_fields |
add other columns to the database (must currently exist on server). "*" will return all table columns available |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default: true) |
saves fishery specimen data as data/raw/fish_specimen_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect("akfin") q_fsh_specimen(year=2022, species=301, area = "goa", db = db) ## End(Not run)## Not run: db <- afscdata::connect("akfin") q_fsh_specimen(year=2022, species=301, area = "goa", db = db) ## End(Not run)
six areas are available to query from bs = bering sea + northwest 1987-present (includes nw stations) - recommended bsslope = bering sea slope nbs = northern bering sea ai = aleutian islands goa = gulf of alaska old_bs = bering sea standard 1982-present (minus ~20 stations in nw) - not recommended
q_gap_biomass( year = 2024, species = 10110, area = "goa", type = "region", design_yr = 2025, db, print_sql = FALSE, save = TRUE )q_gap_biomass( year = 2024, species = 10110, area = "goa", type = "region", design_yr = 2025, db, print_sql = FALSE, save = TRUE )
year |
max year to retrieve data from, and default folder location |
species |
5 digit afsc species code(s) e.g., 79210 or c(79210, 90210) |
area |
options are bs (the bs+nw), bsslope, nbs, ai, goa, old_bs (was called "standard") - can only call a single area |
type |
the goa and ai have: region, reg_area, nmfs_stat_area, stratum, inpfc, inpfc_depth, depth; the bs has: region, subarea, stratum, depth; the bsslope has: region, subarea, stratum; the nbs has region, stratum - can only use a single type (default: "region") |
design_yr |
the survey design year, using multiple will double (or more your values): default 2025 |
db |
the database to query (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) |
save |
save the file in designated folder, if FALSE outputs to global environment |
saves bts biomass data as data/raw/(area)_(type)_bts_biomass_data.csv or outputs to the global environment, also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect() q_gap_biomass(year=2024, species=10110, area="bs", type="region", db=db) ## End(Not run)## Not run: db <- afscdata::connect() q_gap_biomass(year=2024, species=10110, area="bs", type="region", db=db) ## End(Not run)
longline database documentation available on akfin
q_lls_length( year, species, area = c("goa", "bs", "ai"), use_historical = FALSE, db, print_sql = FALSE, save = TRUE )q_lls_length( year, species, area = c("goa", "bs", "ai"), use_historical = FALSE, db, print_sql = FALSE, save = TRUE )
year |
max year to retrieve data from |
species |
5 digit afsc/race species code(s) e.g., 20510 for sablefish or c(30576, 30050) for both shortraker and rougheye/blackspotted |
area |
options are 'goa', 'bs', 'ai', or a combo. default=c('goa', 'bs', 'ai') |
use_historical |
T/F include historical Japanese survey data in the results (default: false) |
db |
the database to query (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) - save must be false |
save |
save the file in designated folder, if FALSE outputs to global environment |
primarily used in stock assessments for calculating sample size tables
sex-specific lengths are collected for sablefish, giant grenadier, spiny dogfish, pacific cod, and greenland turbot (starting in 2021!). sex codes: 1=male, 2=female, 3=unknown
source table on akfin: lls_length_summary_view
saves lls length data as data/raw/lls_length_data.csv or outputs to the global environment. also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: # raw sablefish length frequencies in 1988 (year when the domestic survey started) # in the gulf of alaska db <- connect("akfin") q_lls_length(year=1988, species=20510, area="goa", db=db) ## End(Not run)## Not run: # raw sablefish length frequencies in 1988 (year when the domestic survey started) # in the gulf of alaska db <- connect("akfin") q_lls_length(year=1988, species=20510, area="goa", db=db) ## End(Not run)
longline database documentation available on akfin
q_lls_rpn( year, species, area = c("goa", "bs", "ai"), by = "fmpsubarea", use_historical = FALSE, db, print_sql = FALSE, save = TRUE )q_lls_rpn( year, species, area = c("goa", "bs", "ai"), by = "fmpsubarea", use_historical = FALSE, db, print_sql = FALSE, save = TRUE )
year |
max year to retrieve data from |
species |
5 digit afsc/race species code(s) e.g., 20510 for sablefish or c(30576, 30050) for both shortraker and rougheye/blackspotted |
area |
options are 'goa', 'bs', 'ai', or a combo. default=c('goa', 'bs', 'ai') |
by |
'depth' (stratum-level), 'geoarea' (e.g. Spencer Gully, Kodiak slope), 'councilarea' (e.g., West Yakutat, East Yakutat/Southeast), 'fmpsubarea' (e.g., Eastern Gulf of Alaska), or 'akwide' (only for sablefish). default: 'fmpsubarea' - can only call a single area. note that variances are not available at the depth stratum level (by = 'depth') |
use_historical |
T/F include historical Japanese survey data in the results (default: false) |
db |
the database to query (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) - save must be false |
save |
save the file in designated folder, if FALSE outputs to global environment |
variables of interest: cpue = numbers per skate (1 skate = 45 hooks); relative population numbers (rpns) = area-weighted cpue (area estimates are defined by depth strata and geographic area), relative population weights (rpw) = rpn multiplied by mean fish weight, which is calculated using an allometric relationship and the mean length of fish collected in a given strata and geographic area.
methods for variance estimation of these indices are documented on p 26 the 2016 sablefish safe pdf (p 350 of the goa safe).
the time series starts for the domestic longline survey in the bs and ai starts in 1996, and there are historical data available in the bs/ai from the cooperative Japanese/U.S. survey. in the modern/domestic survey, the eastern ai are surveyed in even years, and the bs is surveyed in odd years. the longline survey does not sample the western ai. estimates in nw and sw ai are based on fixed ratios in the ne and se ai, respectively, from historical cooperative Japanese/U.S. surveys in 1979-1994.
sablefish: includes data from strata 3-7 (depths 201-1000 m) and rpns are adjusted for sperm whale depredation
all other species: includes data from all strata (depths 151-1000 m)
source tables on akfin: lls_area_stratum_rpn lls_area_stratum_rpn_depred lls_area_rpn_all_strata lls_area_rpn_3_to_7 lls_area_rpn_3_to_7_depred lls_council_sablefish_area_all_strata lls_council_sablefish_area_3_to_7_depred lls_fmp_subarea_all_strata lls_fmp_subarea_3_to_7_depred lls_ak_wide_3_to_7_depred
saves lls rpn/rpw data as data/raw/lls_rpn_(by)_data.csv or outputs to the global environment. also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- connect("akfin") # sablefish domestic survey rpn/rpw time series (1990-2022) by goa fmp subarea (wgoa, # cgoa, egoa). note that sablefish rpns are corrected for sperm whale # depredation and only include data from strata 3-7 q_lls_rpn(year=2022, species=20510, area='goa', by='fmpsubarea', db=db, save = FALSE) # pcod domestic survey rpn/rpw time series by bering sea geographic area and # depth stratum. note that the domestic bs time series is odd years starting in # 1997 (ai starts in 1996). q_lls_rpn(year=2022, species=21720, area='bs', by='depth', db=db, save=FALSE) ## End(Not run)## Not run: db <- connect("akfin") # sablefish domestic survey rpn/rpw time series (1990-2022) by goa fmp subarea (wgoa, # cgoa, egoa). note that sablefish rpns are corrected for sperm whale # depredation and only include data from strata 3-7 q_lls_rpn(year=2022, species=20510, area='goa', by='fmpsubarea', db=db, save = FALSE) # pcod domestic survey rpn/rpw time series by bering sea geographic area and # depth stratum. note that the domestic bs time series is odd years starting in # 1997 (ai starts in 1996). q_lls_rpn(year=2022, species=21720, area='bs', by='depth', db=db, save=FALSE) ## End(Not run)
longline database documentation available on akfin
q_lls_rpn_length( year, species, area = c("goa", "bs", "ai"), by = "fmpsubarea", use_historical = FALSE, db, print_sql = FALSE, save = TRUE )q_lls_rpn_length( year, species, area = c("goa", "bs", "ai"), by = "fmpsubarea", use_historical = FALSE, db, print_sql = FALSE, save = TRUE )
year |
max year to retrieve data from |
species |
5 digit afsc/race species code(s) e.g., 20510 for sablefish or c(30576, 30050) for both shortraker and rougheye/blackspotted |
area |
options are 'goa', 'bs', 'ai', or a combo. default=c('goa', 'bs', 'ai') |
by |
'depth' (stratum-level), 'geoarea' (e.g. Spencer Gully, Kodiak slope), 'councilarea' (e.g., West Yakutat, East Yakutat/Southeast), 'fmpsubarea' (e.g., Eastern Gulf of Alaska), or 'akwide' (only for sablefish). default: 'fmpsubarea' - can only call a single area. note that variances are not available at the depth stratum level (by = 'depth') |
use_historical |
T/F include historical Japanese survey data in the results (default: false) |
db |
the database to query (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) - save must be false |
save |
save the file in designated folder, if FALSE outputs to global environment |
sablefish: includes data from strata 3-7 (depths 201-1000 m) and rpns are adjusted for sperm whale depredation
all other species: includes data from all strata (depths 151-1000 m)
sex-specific lengths are collected for sablefish, giant grenadier, spiny dogfish, pacific cod, and greenland turbot (starting in 2021!). sex codes: 1=male, 2=female, 3=unknown
results only include geographic/stratum areas that are used for rpns calc (i.e., exploitable == 1). also ' records with length = 999 have been removed. these records are present in the database to account for instances when there ' was catch in a stratum/station but no lengths collected. the ' 999 lengths ensure rpns sum properly to the area-level but should not be included in the length compositions.
available source tables on akfin: lls_length_area_3_to_7_depred lls_length_area_all_strata
saves lls rpn-weighted length frequency data as data/raw/lls_rpn_length_data.csv or outputs to the global environment. also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: db <- afscdata::connect("akfin") # sablefish domestic longline survey rpn-weighted length frequencies (1990-2022) for # goa and bsai. note that sablefish rpns are corrected for sperm whale # depredation and only include data from strata 3-7 q_lls_rpn_length(year=2022, species=20510, area=c('bsai','goa'), db=db, save=FALSE) # pcod domestic longline survey rpn-weighted length frequencies (1997-2022, # odd years only) for the bering sea q_lls_rpn_length(year=2022, species=21720, area='bs', db=db, save=FALSE) ## End(Not run)## Not run: db <- afscdata::connect("akfin") # sablefish domestic longline survey rpn-weighted length frequencies (1990-2022) for # goa and bsai. note that sablefish rpns are corrected for sperm whale # depredation and only include data from strata 3-7 q_lls_rpn_length(year=2022, species=20510, area=c('bsai','goa'), db=db, save=FALSE) # pcod domestic longline survey rpn-weighted length frequencies (1997-2022, # odd years only) for the bering sea q_lls_rpn_length(year=2022, species=21720, area='bs', db=db, save=FALSE) ## End(Not run)
longline database documentation available on akfin
q_lls_sable_specimen( year, area = c("goa", "bs", "ai"), use_historical = FALSE, db = akfin, print_sql = FALSE, save = TRUE )q_lls_sable_specimen( year, area = c("goa", "bs", "ai"), use_historical = FALSE, db = akfin, print_sql = FALSE, save = TRUE )
year |
max year to retrieve data from |
area |
options are 'goa', 'bs', 'ai', or a combo. default=c('goa', 'bs', 'ai') |
use_historical |
T/F include historical Japanese survey data in the results (default: false) |
db |
the database to query (akfin) |
print_sql |
outputs the sql query instead of calling the data (default: false) - save must be false |
save |
save the file in designated folder, if FALSE outputs to global environment |
source table on akfin: afsc.lls_age_view
saves lls sablefish specimen data as data/raw/lls_specimen_data.csv or outputs to the global environment. also saves a copy of the SQL code used for the query and stores it in the data/sql folder.
## Not run: # sablefish specimen data in 1996 (first year ages were collected in the goa domestic survey) # in the gulf of alaska q_lls_specimen(year=2000, area="goa", db=db) ## End(Not run)## Not run: # sablefish specimen data in 1996 (first year ages were collected in the goa domestic survey) # in the gulf of alaska q_lls_specimen(year=2000, area="goa", db=db) ## End(Not run)
non-target catch estimates by weight (or numbers)
q_nontarget(year, target, area, db, save = TRUE)q_nontarget(year, target, area, db, save = TRUE)
year |
assessment year |
target |
targeted species: 'p' = pollock-mid, 'b' = pollock-bottom, x' = rex, 'h' = shallow flats, 'k' = rockfish, 'w' = arrowtooth, 'c' = pcod, 'i' = halibut |
area |
fmp_area (GOA, BSAI) or fmp_subarea (BS, AI, WG, CG, WY, EY, SE) - also available (SEI, PWSI) |
db |
data server to connect to (akfin) |
save |
save the file in designated folder (default = T) or the global environment |
a csv of non-target species catch by trip target group, saved in the data/output folder
## Not run: akfin = afscdaya::connect() q_nontarget(year=2022, target="k", area="goa", db=akfin, save=FALSE) disconnect(akfin) ## End(Not run)## Not run: akfin = afscdaya::connect() q_nontarget(year=2022, target="k", area="goa", db=akfin, save=FALSE) disconnect(akfin) ## End(Not run)
prohibited species catch (PSC) estimates reported in tons for halibut and herring, counts for salmon, crabs and other fish. Note that you can combine trip target codes c("k", "x") and regions - though results will be lumped together
q_psc(year, target, area, db, save = TRUE)q_psc(year, target, area, db, save = TRUE)
year |
assessment year |
target |
targeted species: 'p' = pollock-mid, 'b' = pollock-bottom, x' = rex, 'h' = shallow flats, 'k' = rockfish, 'w' = arrowtooth, 'c' = pcod, 'i' = halibut |
area |
fmp_area (GOA, BSAI) or fmp_subarea (BS, AI, WG, CG, WY, EY, SE) - also available (SEI, PWSI) |
db |
data server to connect to (akfin) |
save |
save the file in designated folder (default = T) or the global environment |
a csv of prohibited species catch by trip target group, saved in the data/output folder
## Not run: akfin = connect() q_psc(year=2022, target="k", area="goa", db=akfin, save=FALSE) disconnect(akfin) ## End(Not run)## Not run: akfin = connect() q_psc(year=2022, target="k", area="goa", db=akfin, save=FALSE) disconnect(akfin) ## End(Not run)
Query specs
q_specs(year, species, area, db, print_sql = FALSE, save = TRUE)q_specs(year, species, area, db, print_sql = FALSE, save = TRUE)
year |
for specifying the correct folder |
species |
species group code e.g., "DUSK", "PCOD" |
area |
"GOA" or "BSAI" |
db |
data server to connect to (akfin) |
print_sql |
outputs the sql query instead of calling the data - save must be false |
save |
saves a file to the data/raw folder, otherwise sends output to global enviro (default TRUE) |
## Not run: db = connect() q_specs(year=2024, species='PCOD', area='BSAI', db=db, save=F) ## End(Not run)## Not run: db = connect() q_specs(year=2024, species='PCOD', area='BSAI', db=db, save=F) ## End(Not run)
A dataset containing size at age parameters for POP <= 1960
saa_pop_60saa_pop_60
A data frame with 1 observations and 5 variables:
von B parameter
von B parameter
von B parameter
a parameter
b parameter
A dataset containing both fixed gear and trawl gear catch, cpue, rpn & rpw data by year
sabl_fixed_abundancesabl_fixed_abundance
A data frame with 121 observations and 5 variables:
year
weight of catch in 1,000 t, or relative abundance
rpw, rpn, cpue, or catch
japan or domestic
lls = longline survey, llf = longline fishery, tf = trawl fishery
A dataset containing both age and length composition data for multiple fisheries and surveys
sabl_fixed_compssabl_fixed_comps
A data frame with 2010 observations and 7 variables:
year
japan or domestic
age or length
lls = longline survey, tf = trawl fishery, ts = trawl survey
if relevant, otherwise NA
length cm if relevant, otherwise NA
age or length
male, female or NA
A dataset containing area definitions
sabl_new_areassabl_new_areas
A data frame with 15 observations and 2 variables:
area number
assignment for area number
Vessel lengths for calculating whale depredation rates in the sablefish fishery
sabl_vessel_lengthssabl_vessel_lengths
A data frame with 7558 observations and 2 variables:
vessel id
length of the vessel
A dataset containing weights at age for two time blocks, by sex
sabl_waasabl_waa
A data frame with 90 observations and 3 variables:
weight at age
male or female
current or old
Creates a common folder structure for assessment data
setup_folders( year, dirs = c("raw", "user_input", "output", "sara", "sql"), tier = NULL )setup_folders( year, dirs = c("raw", "user_input", "output", "sara", "sql"), tier = NULL )
year |
assessment year |
dirs |
directories to write |
tier |
assessment tier to change the folders used - not currently implemented |
creates a designated/named folder structure
## Not run: setup(2022) ## End(Not run)## Not run: setup(2022) ## End(Not run)
raw data query for GOA/BSAI sharks
sharks(year, area)sharks(year, area)
year |
assessment year |
area |
what region? eith goa or bsai |
a suite of raw data .csv files and a time stamp of when the query was done
## Not run: sharks(year = 2023, area = "goa") ## End(Not run)## Not run: sharks(year = 2023, area = "goa") ## End(Not run)
utility function to filter sql files
sql_filter(sql_precode = "IN", x, sql_code, flag = "-- insert species")sql_filter(sql_precode = "IN", x, sql_code, flag = "-- insert species")
sql_precode |
change input e.g., ("=") |
x |
the variable to change (e.g., year) |
sql_code |
the sql query code... |
flag |
a flag in the sql code to place the precode and x in the appropriate location |
## Not run: .d = sql_filter(sql_precode = "<=", 2011, sql_code = .d, flag = "-- insert year") ## End(Not run)## Not run: .d = sql_filter(sql_precode = "<=", 2011, sql_code = .d, flag = "-- insert year") ## End(Not run)
utility function to read sql file
sql_read(x)sql_read(x)
x |
the sql code to read, pulled from the top directory |
## Not run: .d = sql_read("fsh_catch.sql") ## End(Not run)## Not run: .d = sql_read("fsh_catch.sql") ## End(Not run)
utility function to run sql query
sql_run(database, query)sql_run(database, query)
database |
which database to connect to 'akfin' or 'afsc' |
query |
the sql query code |
## Not run: .d = sql_read("fsh_catch.sql") .d = sql_filter(sql_precode = "<=", 2011, sql_code = .d, flag = "-- insert year") .d = sql_filter(x = area, sql_code = .d, flag = "-- insert region") .d = sql_filter(sql_precode = "IN", x = c("PEL7", "PELS"), sql_code = .d, flag = "-- insert species") afsc = DBI::dbConnect(odbc::odbc(), "afsc", UID = "afsc_user", PWD = "afsc_pwd") sql_run(afsc, query) %>% vroom::vroom_write(here::here(year, 'data', 'raw', 'fsh_catch_data.csv')) DBI::dbDisconnect(afsc) ## End(Not run)## Not run: .d = sql_read("fsh_catch.sql") .d = sql_filter(sql_precode = "<=", 2011, sql_code = .d, flag = "-- insert year") .d = sql_filter(x = area, sql_code = .d, flag = "-- insert region") .d = sql_filter(sql_precode = "IN", x = c("PEL7", "PELS"), sql_code = .d, flag = "-- insert species") afsc = DBI::dbConnect(odbc::odbc(), "afsc", UID = "afsc_user", PWD = "afsc_pwd") sql_run(afsc, query) %>% vroom::vroom_write(here::here(year, 'data', 'raw', 'fsh_catch_data.csv')) DBI::dbDisconnect(afsc) ## End(Not run)