Skip to content

Commit

Permalink
undo everything, add check.duplicates = FALSE to read.snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
orichters committed Oct 8, 2024
1 parent 96c23ef commit c94bb00
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Depends:
Imports:
cli,
countrycode,
data.table,
dplyr (>= 1.1.1),
forcats (>= 1.0.0),
ggplot2,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ import(dplyr)
import(utils)
importFrom(cli,cli_abort)
importFrom(countrycode,countrycode)
importFrom(data.table,fread)
importFrom(dplyr,"%>%")
importFrom(dplyr,across)
importFrom(dplyr,anti_join)
Expand Down
23 changes: 8 additions & 15 deletions R/read.snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
#' read.filter.snapshot("snapshot.csv", list(scenario = c("CurPol", "NDC"), region = "World"))
#' }
#'
#' @importFrom data.table fread
#' @importFrom dplyr filter
#' @importFrom stats setNames
#' @importFrom tidyr pivot_longer
#' @importFrom readxl read_excel excel_sheets
#'
#' @export

Expand Down Expand Up @@ -79,17 +76,13 @@ read.snapshot <- function(file, keep = list(), filter.function = identity) {
data <- filter.function(data)
return(data)
}
if (grepl("\\.rds$", tmpfile)) {
data <- as.quitte(readRDS(tmpfile), na.rm = TRUE)
} else if (grepl("\\.xlsx?$", tmpfile)) {
data <- read_excel(path = tmpfile, sheet = if ("data" %in% excel_sheets(tmpfile)) "data" else 1, guess_max = 21474836) %>%
pivot_longer(matches("[0-9]+"), names_to = "period", values_drop_na = TRUE)
} else {
sep <- if (grepl(",", read_lines(file = tmpfile, n_max = 1), fixed = TRUE)) "," else ";"
data <- fread(tmpfile, sep = sep, header = TRUE, na.strings = c("UNDF", "NA", "N/A", "n_a", "")) %>%
as_tibble() %>%
pivot_longer(matches("[0-9]+"), names_to = "period", values_drop_na = TRUE)
}
# read file and do correct filtering
data <- read.quitte(tmpfile,
na.strings = c("UNDF", "NA", "N/A", "n_a", ""),
quote = '"',
drop.na = TRUE,
check.duplicates = FALSE,
filter.function = joinedfilter)
unlink(tmpfile)
return(joinedfilter(as.quitte(data)))
return(data)
}

0 comments on commit c94bb00

Please sign in to comment.