Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ybkamaleri committed Aug 14, 2023
2 parents 623dbcb + 8e4f693 commit e917cd3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orgdata
Title: Aggregating Original Data
Version: 1.3.6
Version: 1.4.0
Authors@R:
c(person(given = "Yusman",
family = "Kamaleri",
Expand All @@ -24,7 +24,7 @@ Depends:
Imports:
data.table (>= 1.14.6),
DBI (>= 1.1.3),
norgeo (>= 2.1.0),
norgeo (>= 2.2.0),
odbc (>= 1.3.4),
R6 (>= 2.5.1),
readxl (>= 1.4.1),
Expand All @@ -43,7 +43,8 @@ Imports:
cli (>= 3.4.0)
Remotes:
ybkamaleri/praise,
hadley/emo
hadley/emo,
helseprofil/norgeo
Suggests:
testthat (>= 3.0.0),
tibble (>= 3.1.4),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# orgdata 1.4.0 (dev)
- Refactor some codes.
- Specify encoding via config.yml file.
- Use `norgeo` package from Github ie. dev, instead of CRAN.

# orgdata 1.3.6
- Fix selecting files without `KOBLID` (#315)
Expand Down
2 changes: 1 addition & 1 deletion R/connect-db.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ connect_db <- function(dbname, dbtype, dbyear, dbdriver){
Access = {
DBI::dbConnect(odbc::odbc(),
.connection_string = paste0(dbdriver, dbname),
encoding = "latin1")
encoding = getOption("orgdata.encoding"))
},
DuckDB = {
duckRoot <- duck_db_path(dbname, dbyear, file = FALSE)
Expand Down
40 changes: 19 additions & 21 deletions R/make-file-each.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,37 +124,35 @@ do_make_file_each <- function(spec, fgspec, aggregate, datacols, year, row, base


## Add to or read from DuckDB -------------
## TODO Need to refactor the codes below
## To use if..else.. makes the codes difficult to read
fileName <- find_column_input(fileSpec, "FILNAVN")
fileName <- paste0("../", gsub("\\\\", "/", fileName))

if (!fileCtrl && fileDuck){
is_verbose(msg = is_line_short(), type = "other", ctrl = FALSE)
withr::with_options(list(orgdata.emoji = "safe"),
is_color_txt(x = "",
msg = "Delete dataset in the data warehouse ...",
type = "debug", emoji = TRUE))
duck$db_remove_table(name = duckTbl)
opt <- "option1"
optMsg <- "Delete dataset in the data warehouse ..."
} else if (fileCtrl && !fileDuck){
opt <- "option2"
optMsg <- "Adding dataset to data warehouse ..."
} else if (fileCtrl && fileDuck){
opt <- "option3"
optMsg <- "Data found in data warehouse! To read from raw data uncheck KONTROLLERT or use `raw=TRUE` instead"
} else {
opt <- "option4"
}

if (fileCtrl && !fileDuck){
if (opt != "option4"){
is_verbose(msg = is_line_short(), type = "other", ctrl = FALSE)
withr::with_options(list(orgdata.emoji = "safe"),
is_color_txt(x = "",
msg = "Adding dataset to data warehouse ...",
type = "debug", emoji = TRUE))
duck$db_write(name = duckTbl, value = dt, write = TRUE)
is_color_txt(x = "", msg = optMsg, type = "debug", emoji = TRUE))
}

if (fileCtrl && fileDuck){
withr::with_options(list(orgdata.emoji = "safe"),
is_color_txt(x = "",
msg = "Data found in data warehouse! To read from raw data uncheck KONTROLLERT or use `raw=TRUE` instead",
type = "debug", emoji = TRUE))
is_color_txt(x = fileName, msg = "File:")
dt <- duck$db_read(name = duckTbl)
}
switch(opt,
option1 = duck$db_remove_table(name = duckTbl),
option2 = duck$db_write(name = duckTbl, value = dt, write = TRUE),
option3 = {
is_color_txt(x = fileName, msg = "File:")
dt <- duck$db_read(name = duckTbl)
})

data.table::copy(dt)
}
Expand Down
1 change: 1 addition & 0 deletions R/make-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ make_file <- function(group = NULL,
save_file(dt = outDT, name = group, fgSpec = fgSpec)
}

is_verbose(msg = is_line_short(), type = "other", ctrl = FALSE)
is_color_txt(x = group,
msg = "Completed filegroup:",
type = "note",
Expand Down
3 changes: 2 additions & 1 deletion docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e917cd3

Please sign in to comment.