Skip to content

Commit

Permalink
Improved robustness of function classify_kmeans
Browse files Browse the repository at this point in the history
  • Loading branch information
alesantuz committed Nov 22, 2024
1 parent a9e4aed commit a3b5bec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: musclesyneRgies
Title: Extract Muscle Synergies from Electromyography
Version: 1.2.5.9007
Version: 1.2.5.9008
Authors@R:
person("Alessandro", "Santuz", , "alessandro.santuz@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-6577-5101"))
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# musclesyneRgies 1.2.5.9008 (development version)
### How to install
```
install.packages("remotes")
remotes::install_github("alesantuz/musclesyneRgies")
```
### How to use
README and vignettes are available both on [CRAN](https://CRAN.R-project.org/package=musclesyneRgies) and on [GitHub](https://github.com/alesantuz/musclesyneRgies).

### What's changed
- Improved robustness of function `classify_kmeans`, which can now deal with trial names containing dots.

# musclesyneRgies 1.2.5.9007 (development version)
### How to install
```
Expand Down
13 changes: 11 additions & 2 deletions R/classify_kmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,17 @@ classify_kmeans <- function(x,
syn0 <- which(!duplicated(trials))
trials <- make.unique(trials)
trials[syn0] <- paste0(trials[syn0], "_Syn0")
# Assign incremental Syn number to other names
trials <- gsub("\\.", "_Syn", trials)
# Assign incremental Syn number to other names.
# The following is written like that to consider trial names
# that might contain dots. The Perl-style positive lookahead
# ensures that the dot is followed by zero or more characters
# that are not dots ([^.]), all the way to the end of the string ($).
# The conditional element excludes trials ending with "_Syn0".
trials <- ifelse(
grepl("_Syn0$", trials),
trials,
gsub("\\.(?=[^.]*$)", "_Syn", trials, perl = TRUE)
)
# Start from Syn1 instead that from Syn0
temp1 <- gsub("[0-9]$", "", trials)
temp2 <- as.numeric(gsub(".*_Syn", "", trials)) + 1
Expand Down

0 comments on commit a3b5bec

Please sign in to comment.