usa_pull_data: Pull data from U.S. databases for Pacific Hake

View source: R/utils-usa-pull-data.R

usa_pull_dataR Documentation

Pull data from U.S. databases for Pacific Hake

Description

Extraction of

  • catch data,

  • weight measurements,

  • length measurements,

  • age reads, and

  • management quantities from NORPAC and PacFIN databases for the Pacific Hake assessment.

Usage

usa_pull_data(
  password_file,
  start_year = 1900,
  end_year = get_data_yr(),
  save_dir = fs::path(here::here(), "data-tables")
)

Arguments

password_file

A file path specifying where to find the passwords. The path can be full or relative to your current working directory. The text file must contain two lines, where the first line is the NORPAC password and the second line is the PacFIN password. These passwords should not be surrounded with quotes. If a file name is not provided, which is the default behavior, then the user will be prompted for their passwords. This also happens if the file cannot be found given the path provided. These passwords are needed because the databases store confidential information.

start_year

An integer value specifying the start year of data to include in the extraction. The default is 1900 to include all the data possible, including years where only a foreign fleet fished.

end_year

An integer value specifying the final year of data to include in the extraction. The default uses get_data_yr() to determine the terminal year.

save_dir

A string specifying the full path to a directory where you want files saved. The default is to save them in a folder found using fs::path(here::here(), "data-tables")(), which returns a path specific to the personal preferences of JTC members.

Details

usa_pull_data() includes several steps, outlined below, and leads to many files being saved to your computer. Originally, files were NOT overwritten. In 2022, Kelli F. Johnson changed the code to not save previous downloads to save on disk space, reduce the storing of redundant information, and simplify the code base that needed maintenance. The code steps through the following steps:

  • Assign usernames and passwords, where the latter are read in from the specified file or obtained from the user.

  • Find the folder where the data should be saved, typically using fs::path(here::here(), "data-tables")().

  • Extract data from NORPAC.

    • Catch data

    • Weight and age data

    • Squash table of ages (that also includes lengths)

    • Foreign ages

    • Species list

  • Extract data from PacFIN.

    • Catch data

    • Age, length, and weight data from bds table

    • At-sea data

    • Management quantities such as allowable catch limits (ACL) for the Pacific Fisheries Management Council, i.e., U.S. quantities of interest.

  • Save each object to the disk in the "extractedData" directory, which is created in the directory specified by save_dir if it does not already exist.

Value

An environment or list with several objects pulled from the desired databases are returned invisibly. Additionally, several .Rdat files are saved to the disk in extractedData, which is created inside of save_dir. The following files are saved:

  • nages.Rdat

  • nweight.Rdat

  • ncatch.Rdat

  • page.Rdat

  • pcatch.Rdat

  • pspec.Rdat

Author(s)

Kelli F. Johnson

See Also

  • get_data_yr()

Examples

## Not run: 
# An environment with objects is returned
dataenv <- usa_pull_data()
# Access individual objects using `get()`
head(get("ncatch", envir = dataenv))
# Access individual objects pretending the environment is a list
dataenv[["ncatch"]][1:5, ]

## End(Not run)


pacific-hake/hake-assessment documentation built on Jan. 14, 2025, 9:12 p.m.