Skip to content

Commit

Permalink
fixed #13
Browse files Browse the repository at this point in the history
Modif manipulateAllTypeDays
  • Loading branch information
JulienBretteville committed Aug 6, 2019
1 parent bda2174 commit 129fe94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 14 additions & 6 deletions R/manipulateAllTypeDays.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ manipulateAllTypeDays <- function(allTypeDay, output) {
class <- unique(allTypeDay[, Class])
if (output == "vertices") {

lenDiffCols <- length(unique(sapply(1:nrow(allTypeDay), function(X) {
colnames(allTypeDay[, dayIn][[X]][, VERT_details][[1]])
})))

colorder <- colnames(allTypeDay[, dayIn][[1]][, VERT_details][[1]])
if(lenDiffCols > 1) {
colorder <- colorder[!grepl("N|nbsign|sign", colorder)]
}
dt_output <- rbindlist(sapply(class, function(cl) {

# remove NOTE data.table
Expand All @@ -71,11 +78,12 @@ manipulateAllTypeDays <- function(allTypeDay, output) {
data <- rbindlist(sapply(unique(data[, idDayType]), function(X) {

lst <- data[idDayType == X, dayIn][[1]][, VERT_details]
if (!(all(colnames(lst[[1]]) == colorder))) {
for (i in 1:length(lst)) {
setcolorder(lst[[i]], colorder)
}
# if (!(all(colnames(lst[[1]]) == colorder))) {
for (i in 1:length(lst)) {
lst[[i]] <- lst[[i]][, .SD, .SDcols = colorder]
setcolorder(lst[[i]], colorder)
}
# }

if (class(lst[[1]]$Date) == "Date") {
for (i in 1:length(lst)) {
Expand Down Expand Up @@ -111,7 +119,7 @@ manipulateAllTypeDays <- function(allTypeDay, output) {
setcolorder(lst[[i]], colorder)
}
}

if (class(lst[[1]]$Date) == "Date") {
for (i in 1:length(lst)) {
lst[[i]]$Date <- as.character(lst[[i]]$Date)
Expand Down Expand Up @@ -157,7 +165,7 @@ manipulateAllTypeDays <- function(allTypeDay, output) {

data.table(rbindlist(lst), Class = cl, idDayType = X)


}, simplify = F))
data
}, simplify = F))
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-manipulateAllTypeDays.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ test_that("manipulateAllTypeDays", {
PLAN_raw_target, PLAN_raw[, .SD, .SDcols = colnames(PLAN_raw)[!grepl(
"Class|idDayType", colnames(PLAN_raw))]]))
expect_true(all.equal(
VERT_target, VERT[, .SD, .SDcols = colnames(VERT)[!grepl(
VERT_target[, .SD, .SDcols = colnames(VERT)[!grepl(
"Class|idDayType", colnames(VERT))]], VERT[, .SD, .SDcols = colnames(VERT)[!grepl(
"Class|idDayType", colnames(VERT))]]))

})

0 comments on commit 129fe94

Please sign in to comment.