Skip to content
Merged
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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spiro (development version)
===========================


* Fix bug in Cosmed import leading to failure in rare cases

spiro 0.2.3 (2025-02-18)
===========================
Expand Down
16 changes: 11 additions & 5 deletions R/spiro_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ spiro_get_cosmed <- function(file) {
bodymass = as.numeric(
get_meta(
tbl,
c("Weight (Kg):", "Weight (Kg)", "Gewicht (Kg):", "Gewicht (Kg)")
c("Weight (Kg):", "Weight (Kg)", "Gewicht (Kg):", "Gewicht (Kg)",
"Weight (kg):", "Weight (kg)", "Gewicht (kg):", "Gewicht (kg)")
)
)
)
Expand Down Expand Up @@ -308,10 +309,15 @@ spiro_get_cosmed <- function(file) {
# rare special case if body mass has been deleted from meta data. Recalculates
# body mass based on relative oxygen uptake present in raw data
if (is.na(info$bodymass)) {
info$bodymass <- round(
# used first data value to recalculate body mass
as.numeric(data$VO2[[1]]) / as.numeric(data$`VO2/Kg`[[1]]), 1
)
if (any(colnames(data) == "VO2/Kg")) {
info$bodymass <- round(
as.numeric(data$VO2[[1]]) / as.numeric(data$`VO2/Kg`[[1]]), 1
)
} else if (any(colnames(data) == "VO2/kg")) {
info$bodymass <- round(
as.numeric(data$VO2[[1]]) / as.numeric(data$`VO2/kg`[[1]]), 1
)
}
}

attr(df, "info") <- info # write meta data
Expand Down
Binary file modified tests/testthat/testdata/cosmed.xlsx
Binary file not shown.
Loading