Skip to content

Commit

Permalink
Merge branch 'issue-10' of https://github.com/mhpob/otndo into issue-10
Browse files Browse the repository at this point in the history
  • Loading branch information
mhpob committed Jun 21, 2024
2 parents 6e54d63 + 94a60da commit 82cb5f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
37 changes: 18 additions & 19 deletions R/utilities_make.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ clean_otn_deployment <- function(deployment) {
# Find which sheet has deployment data. If none are explicitly labeled, assume
# it's sheet 1
sheet_id <- grep("dep", readxl::excel_sheets(deployment),
ignore.case = T, value = T
ignore.case = T, value = T
)
if (length(sheet_id) == 0) {
sheet_id <- 1
}

# Check for header: If the first row has no columns, it likely contains it.
if (ncol(readxl::read_excel(deployment,
sheet = sheet_id,
range = "A1"
sheet = sheet_id,
range = "A1"
)) == 0) {
deployment <- readxl::read_excel(deployment,
sheet = sheet_id,
skip = 3
sheet = sheet_id,
skip = 3
)
} else {
deployment <- readxl::read_excel(deployment, sheet = sheet_id)
Expand All @@ -38,12 +38,12 @@ clean_otn_deployment <- function(deployment) {
check_head <- read.csv(deployment, nrows = 1, check.names = FALSE)
if (ncol(check_head) > length(unique(names(check_head)))) {
deployment <- read.csv(deployment,
skip = 3,
na.strings = c("NA", "")
skip = 3,
na.strings = c("NA", "")
)
} else {
deployment <- read.csv(deployment,
na.strings = c("NA", "")
na.strings = c("NA", "")
)
}
} else {
Expand All @@ -63,10 +63,10 @@ clean_otn_deployment <- function(deployment) {
deployment$recover_date_time <- convert_times(deployment$recover_date_time)

deployment <- deployment[!is.na(deployment$deploy_date_time) &
!is.na(deployment$recover_date_time), ]
!is.na(deployment$recover_date_time), ]
deployment$receiver <- paste(deployment$ins_model_no,
deployment$ins_serial_no,
sep = "-"
deployment$ins_serial_no,
sep = "-"
)
deployment$stationname <- deployment$station_no

Expand All @@ -86,16 +86,15 @@ clean_otn_deployment <- function(deployment) {

#' @rdname utilities-make
#' @keywords internal
convert_times <- function(date_time){

check_times <- function(x){
convert_times <- function(date_time) {
check_times <- function(x) {
# check if Excel format
# Assumes that it starts with 5 numbers
if (grepl('^\\d{5}', x)) {
if (grepl("^\\d{5}", x)) {
as.POSIXct(
as.numeric(x) * (60 * 60 * 24),
tz = "UTC",
origin = '1899-12-30'
origin = "1899-12-30"
)
} else {
as.POSIXct(
Expand Down Expand Up @@ -123,8 +122,8 @@ provided_file_unzip <- function(files, temp_dir) {
to_unzip,
function(.) {
unzip(.,
exdir = temp_dir,
setTimes = FALSE
exdir = temp_dir,
setTimes = FALSE
)
}
)
Expand Down Expand Up @@ -158,7 +157,7 @@ write_to_tempdir <- function(type, files, temp_dir) {
## Write file to temporary directory
filepath <- file.path(temp_dir, paste0(type, ".csv"))
write.csv(files, filepath,
row.names = F
row.names = F
)


Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-convert_times.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
test_datetime <- as.POSIXct("2020-04-09T11:04:59", tz = "UTC",
format = "%Y-%m-%dT%H:%M:%S")
test_datetime <- as.POSIXct("2020-04-09T11:04:59",
tz = "UTC",
format = "%Y-%m-%dT%H:%M:%S"
)

test_that("converts ISO 8601", {
expect_equal(
Expand Down

0 comments on commit 82cb5f7

Please sign in to comment.