Skip to content

Commit

Permalink
Merge branch 'master' of github.com:luckinet/tabshiftr
Browse files Browse the repository at this point in the history
  • Loading branch information
EhrmannS committed Dec 5, 2023
2 parents 319b36c + 1d4b0a5 commit 1c13267
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tabshiftr
Title: Reshape Disorganised Messy Data
Version: 0.4.1
Version: 0.4.2
Authors@R:
c(person(given = "Steffen",
family = "Ehrmann",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# tabshiftr 0.4.2

- include split and merge functionality for cluster ID.

# tabshiftr 0.4.1

- adapt to update of dplyr
Expand Down
29 changes: 28 additions & 1 deletion R/getClusterVar.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#' getClusterVar(input = input)
#' @importFrom checkmate assertTRUE
#' @importFrom purrr map set_names
#' @importFrom tidyr extract
#' @export

getClusterVar <- function(schema = NULL, input = NULL){
Expand Down Expand Up @@ -69,7 +70,33 @@ getClusterVar <- function(schema = NULL, input = NULL){
theCols <- c(clusters$col[ix]:(clusters$width[ix]+clusters$col[ix]-1))
theCols <- theCols[theCols %in% filter$col]
}
input[theRows, theCols]
temp <- input[theRows, theCols]


# split ...
if(!is.null(theVar$split)){
# need to distinguish between one and several columns
if(dim(temp)[2] == 1){
temp <- temp %>%
tidyr::extract(col = 1, into = names(temp), regex = paste0("(", theVar$split, ")"))
} else {
temp <- map_dfc(.x = seq_along(temp), .f = function(iy){
temp %>%
select(all_of(iy)) %>%
extract(col = 1, into = names(temp)[iy], regex = paste0("(", theVar$split, ")"))
})
}
}

# ... or merge the variable
if(!is.null(theVar$merge)){
newName <- paste0(names(temp), collapse = theVar$merge)
temp <- temp %>%
unite(col = !!newName, sep = theVar$merge)
}

temp

})
names(out) <- rep(clusters$id, nClusters)

Expand Down
2 changes: 0 additions & 2 deletions R/reorganise.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

reorganise <- function(input = NULL, schema = NULL){

# library(tidyverse); library(rlang); library(checkmate)

# check validity of arguments
assertDataFrame(x = input)

Expand Down

0 comments on commit 1c13267

Please sign in to comment.