Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error when removing duplicate columns #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions R/check_availability.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ check_availability <- function(records, verbose = TRUE){

# extract order ids of last 7 days
order_ids <- gsub('\\["', "", gsub('"]', "", strsplit(xml_text(xml_children(order_ids)[[1]]), '\", \"')[[1]]))
order_dates <- lapply(order_ids, function(x) strptime(strsplit(x, "-")[[1]][3], format = "%m%d%Y"))
# get third to last string of split, thereby ignoring possible hyphens in account e-mail-adress
order_dates <- lapply(order_ids, function(x) strptime(strsplit(x, "-")[[1]][length(strsplit(x, "-")[[1]])-2], format = "%m%d%Y"))
order_ids <- order_ids[sapply(order_dates, function(x) difftime(Sys.time(), x, units = "days")) <= 7]

# if there is something, digg deeper
Expand All @@ -76,7 +77,7 @@ check_availability <- function(records, verbose = TRUE){
# extract order ids that match records and are still hot for download
records[sub,]$gSD.order_id <- .sapply(records[sub,]$record_id, function(recid){
match_item <- .sapply(item_ids, function(itid) recid %in% itid)
if(any(match_item)) order_ids[match_item] else NA
if(any(match_item)) order_ids[match_item][1] else NA
})
#records[sub,][records[sub,]$record_id %in% unlist(item_ids),]$gSD.order_id <- order_ids[unlist(item_ids) %in% records[sub,]$record_id]
#records[sub,]$gSD.order_id <- order_ids[sapply(records[sub,]$record_id, function(x) which(x == item_ids)[1])]
Expand Down Expand Up @@ -124,4 +125,4 @@ check_availability <- function(records, verbose = TRUE){
out(paste0(as.character(n_avail), "/", nrow(records), " records are currently available for download (this includes past completed orders that are still available for download)."), type = 1)
if(n_avail < nrow(records)) out("Use order_data() to order/restore records that are not available for download.")
return(.column_summary(records, records.names))
}
}
5 changes: 4 additions & 1 deletion R/internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@
records$stop_time <- as.POSIXct(strptime(records$stop_time, "%Y:%j:%T", tz = "UTC"))
records$date_acquisition <- as.Date(records$start_time)
records$start_date <- records$stop_date <- NULL
records[, which(colnames(records) == "cloudcov")[2]] <- NULL #remove duplicated column
# Find and remove Duplicated Columns
duplicated_columns <- duplicated(as.list(records))
records <- records[!duplicated_columns]
#records[, which(colnames(records) == "cloudcov")[2]] <- NULL #remove duplicated column
}
if(product_group == "modis"){
records$start_time <- as.POSIXct(strptime(records$start_date, "%Y-%m-%d %T", tz = "UTC"))
Expand Down