Skip to content

Commit 48fb088

Browse files
committed
edited to take username as an input
1 parent 42414ba commit 48fb088

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

data-raw/compare_comlandr_stocksmart.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
# and geographic area mismatches.
88
# Updates: Grouped skate complex, removed foreign landings, isolated overages,
99
# dynamically converted complex units (e.g., 'Thousand lbs'),
10-
# capped visual outliers, and hardcoded BSB stock exception.
10+
# capped visual outliers, hardcoded BSB stock exception,
11+
# and added dynamic username prompt.
1112
# =========================================================================
1213

1314
# 1. Setup & Load Libraries -----------------------------------------------
@@ -18,6 +19,14 @@ library(data.table)
1819
library(dbutils)
1920
library(DBI)
2021

22+
# Prompt for database username
23+
if (interactive()) {
24+
db_username <- readline(prompt = "Enter your NEFSC database username: ")
25+
if (trimws(db_username) == "") stop("Username cannot be blank.")
26+
} else {
27+
stop("This script must be run interactively to enter a database username.")
28+
}
29+
2130
start_year <- 1985
2231
end_year <- as.integer(format(Sys.Date(), "%Y")) - 1
2332

@@ -33,7 +42,7 @@ if (!dir.exists("data-raw")) {
3342
}
3443

3544
# 2. Pull Data from NEFSC Database ----------------------------------------
36-
channel <- dbutils::connect_to_database("NEFSC_pw_oraprod", "MGREZLIK")
45+
channel <- dbutils::connect_to_database("NEFSC_pw_oraprod", db_username)
3746

3847
# Create a master area map covering all possible US statistical areas (1 to 999)
3948
coastwide <- data.table(AREA = 1:999, EPU = "Coastwide")
@@ -227,7 +236,7 @@ chunk_size <- 6
227236

228237
for (i in seq(1, length(species_list), by = chunk_size)) {
229238
target_spp <- species_list[i:min((i + chunk_size - 1), length(species_list))]
230-
239+
231240
p <- hypothesis_df |>
232241
filter(Species %in% target_spp) |>
233242
group_by(Species) |>
@@ -263,7 +272,7 @@ for (i in seq(1, length(species_list), by = chunk_size)) {
263272
color = "Data Source"
264273
) +
265274
theme(legend.position = "bottom")
266-
275+
267276
print(p)
268277
}
269278

0 commit comments

Comments
 (0)