BREAKING CHANGES in Version 2.0.0️
Major changes that will impact some users:
- Oracle connections - Some functions now require existing oracle connections (
cxn) instead of username/password - Data encryption - Protected B data is now encrypted when extracted
- Deprecated parameters - Some older parameter names removed (see migration guide)
Why these changes? See NEWS.md for detailed explanation.
This is a comprehensive suite of utility functions used by various Maritimes R packages and useful for general fisheries data analysis. This package contains functions that are both useful standalone or were developed to support other packages in the Maritimes ecosystem.
Key capabilities:
- Database extraction and connection management
- Spatial data processing and analysis
- VMS data cleaning and analysis
- Privacy assessment and data aggregation
- File management and data export
- General utilities for data manipulation
# Install from GitHub
library(devtools)
install_github('Maritimes/Mar.utils')library(Mar.utils)
# Connect to Oracle database
cxn <- ROracle::dbConnect(DBI::dbDriver("Oracle"), <"oracle.username">", <"oracle.password">", "PTRAN")
# Extract custom tables
get_data_tables(schema = "MARFISSCI",
tables = c("MARFLEETS_LIC", "NAFO_UNIT_AREAS"),
cxn = cxn)
# Work with spatial data
my_sf <- df_to_sf(my_dataframe, type = "points")
clipped_data <- clip_by_poly(my_sf, clip.poly = "study_area.shp")Extract data from DFO Oracle databases
get_data_tables()- Extract specific tables from any schemamake_oracle_cxn()- Create Oracle database connectionsconnectionCheck()- Validate connection typesdeprecationCheck()- Check for deprecated parameters
# Extract custom tables
cxn <- ROracle::dbConnect(DBI::dbDriver("Oracle"), <"oracle.username">", <"oracle.password">", "PTRAN")
get_data_tables(schema = "MARFISSCI", tables = "MARFLEETS_LIC", cxn = cxn)Process and analyze spatial fisheries data
df_to_sf()- Convert dataframes to spatial objects (points, lines, polygons)clip_by_poly()- Clip data to geographic areasidentify_area()- Determine which area/zone points fall withinmake_segments()- Create line segments from coordinate tracksmake_segments_isdb()- Specialized segments for ISDB fishing setsdf_qc_spatial()- Quality control spatial coordinatesdf_sf_to_gpkg()- Export spatial data to GeoPackage formatgpkglayers_to_shapefiles()- Convert GeoPackage layers to shapefilesprepare_shape_fields()- Prepare field names for shapefile export
# Create fishing tracks from VMS data
tracks <- make_segments(vms_data, objField = "VR_NUMBER",
seqField = "POSITION_UTC_DATE")
# Identify NAFO areas for fishing sets
sets_with_nafo <- identify_area(fishing_sets,
agg.poly.field = "NAFO")Assess and aggregate sensitive fisheries data following DFO protocols
assess_privacy()- Apply Rule of 5 and aggregate sensitive dataaggregator()- Aggregate coordinates into gridded summariesplot_hex_data()- Visualize aggregated hex/grid data
# Aggregate sensitive commercial data following Rule of 5
results <- assess_privacy(df = commercial_data,
sens.fields = c("LICENCE_ID", "VR_NUMBER"),
agg.fields = c("KEPT_WT", "DISCARD_WT"))** For detailed privacy workflows, see:** vignette("assess_privacy", package = "Mar.utils")
Clean and analyze Vessel Monitoring System data
VMS_get_recs()- Extract VMS records from databaseVMS_clean_recs()- Clean and filter VMS tracksVMS_from_MARFIS()- Match VMS data with MARFIS fishing activitysubset_by_time()- Filter records by minimum time intervals
# Extract and clean VMS data
raw_vms <- VMS_get_recs(cxn = cxn, dateStart = "2023-01-01",
vrnList = c("12345", "67890"))
clean_vms <- VMS_clean_recs(raw_vms, minDist_m = 100, maxBreak_mins = 1440)Transform and clean fisheries datasets
dets_defuddler()- Convert MARFIS detail tables from long to wide formatDDMMx_to_DD()- Convert coordinates from DDMM format to decimal degreesISSETPROFILE_enwidener()- Reshape ISDB set profile datarename_fields()- Rename dataframe columnsdrop_cols()- Remove columns based on uniformity criteriaclean_dfo_fields()- Remove standard DFO housekeeping fields
# Convert MARFIS details to usable format
wide_data <- dets_defuddler(marfName = "LOG_EFRT_ENTRD_DETS",
df = effort_details)
# Convert coordinates
coords_df <- DDMMx_to_DD(my_data, format = "DDMMMM",
lat.field = "LAT", lon.field = "LON")Secure data storage and file operations
save_encrypted()- Save data files with encryption for Protected B dataload_encrypted()- Load encrypted data filesdata.dir_valet()- Clean up and organize data directories
# Save sensitive data securely
save_encrypted(sensitive_data, file = "protected_data.RData", encrypt = TRUE)
# Load data extracted by another user/computer
load_encrypted("protected_data.RData",
extract_user = "original_user",
extract_computer = "COMPUTER123")Helper functions for data analysis
big_in()- Create SQL IN statements for large vectors (>1000 items)SQL_in()- Convert vectors to SQL IN formatMode()- Calculate statistical modest_err()- Calculate standard errorcombine_lists()- Merge lists with conflict resolutionupdateCheck()- Check for package updates on GitHub
Tools for troubleshooting and quality control
changeDetector()- Track changes in dataframes during processingwhere_now()- Display current function location for debuggingupdateExpected()- Track expected values through processing steps
Handle temporal data consistently
vali_dates()- Validate and standardize date inputssimple_date()- Convert datetime fields to simple dates
Specialized functions for survey design
set_select()- Generate randomized survey station locations
Functions with new requirements:
# OLD - some functions accepted credentials directly
get_data_tables(schema = "MARFISSCI", tables = "MARFLEETS_LIC", username = "user", password = "pass", dsn = "PTRAN, usepkg='roracle")
# NEW - cleaner connection establishment
cxn <- ROracle::dbConnect(DBI::dbDriver("Oracle"), <"oracle.username">", <"oracle.password">", "PTRAN")
get_data_tables(schema = "MARFISSCI", tables = "MARFLEETS_LIC", cxn = cxn)- Mar.datawrangling - Database extraction and filtering
- Mar.fleets - Fleet analysis tools
- Mar.data - Reference spatial datasets
- Check NEWS.md for recent changes
- Browse function documentation:
?function_name - View vignettes:
browseVignettes("Mar.utils") - Contact: mike.mcmahon@dfo-mpo.gc.ca
- Report issues: GitHub Issues
A suite of functions used by various Maritimes packages - Version 2.0.0