Skip to content

Commit 4e114b9

Browse files
gergnessmalecki
authored andcommitted
oops
1 parent ff7ab66 commit 4e114b9

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

R/folders.R

+8-16
Original file line numberDiff line numberDiff line change
@@ -399,22 +399,14 @@ organize_recurse <- function(base, base_type, path) {
399399
} else {
400400
# Make sequences where each folder is on its own, and the variables
401401
# at the folder level are in sequence. This allows the organize folder
402-
# to go in the right place so that the folder is organized among the vas
403-
folder_pos <- which(types(items) == "folder")
404-
# starts are 1, the folder positions, and 1 after the folder positions so that
405-
# each folder gets split out on its own. If position is to high, needs to be
406-
# replaced with length, which can happen if a folder is in last position
407-
starts <- pmin(c(1, folder_pos + c(0, 1)), length(items))
408-
# and ends are one less than the folders, the folder positions and the length of
409-
# the list. Need to replace item less than 1, which can occur if folder is in
410-
# first position
411-
ends <- pmax(c(folder_pos - c(1, 0), length(items)), 1)
412-
413-
split_items <- mapply(
414-
FUN = function(starts, ends) items[seq(starts, ends)],
415-
starts = starts,
416-
ends = ends
417-
)
402+
# to go in the right place so that the folder is organized among the vars
403+
is_folder <- types(items) == "folder"
404+
prev_was_folder <- c(FALSE, is_folder[-length(is_folder)])
405+
groups <- cumsum(is_folder | prev_was_folder)
406+
407+
split_items <- lapply(unique(groups), function(grp) {
408+
items[groups == grp]
409+
})
418410
}
419411

420412
lapply(

0 commit comments

Comments
 (0)