Skip to content

Commit

Permalink
Output formatting tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bpbond committed Nov 24, 2023
1 parent 3961d44 commit dce9f69
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion synoptic/L1.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ f <- function(dir_name, dirs_to_process, out_dir) {
if(nrow(flg)) {
flg$Flag_type <- "OOB"
flg$Remark <- basename(dir_name)
message("\tSending ", nrow(flg), " flags to database")
message("Sending ", nrow(flg), " flags to database")
fdb_add_flags(site, flg)
}
Expand Down
7 changes: 3 additions & 4 deletions synoptic/flag-database.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ fdb_open <- function(root, init = FALSE) {
fdb_add_flags <- function(site, flag_data, fdb = FDB) {
if(site %in% dbListTables(fdb)) {
# We don't want to create identical rows
# The SQLite way to do this would be using UPDATE or REPLACE, but
# given our small data volumes, it seems simpler to use R's duplicated()
# Given our small data volumes, seems simplest to use R's duplicated()
old_data <- dbReadTable(fdb, site)
new_data <- rbind(old_data, flag_data)
new_data <- new_data[!duplicated(new_data),]
dbWriteTable(fdb, site, new_data, overwrite = TRUE)
rows <- nrow(new_data) - nrow(old_data)
} else {
message("Creating new site ", site)
message("\tCreating new site ", site)
dbWriteTable(fdb, site, flag_data)
rows <- nrow(flag_data)
}
message("Added ", rows, " rows")
message("\tAdded ", rows, " rows")
}

# Get flag data for a single site
Expand Down
2 changes: 1 addition & 1 deletion synoptic/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ write_to_folders <- function(x, root_dir, data_level, site,
basename(folder), "/", filename)

fn <- file.path(folder, filename)
if(file.exists(fn)) message("NOTE: overwriting existing file")
if(file.exists(fn)) message("\tNOTE: overwriting existing file")
# We were using readr::write_csv for this but it was
# randomly crashing on GA (Error in `vroom write()`: ! bad value)
write.csv(dat, fn, row.names = FALSE, na = na_string)
Expand Down

0 comments on commit dce9f69

Please sign in to comment.