Skip to content

Commit 9cc1f3f

Browse files
committed
get_wave to support decimal wave numbers
1 parent 1f359bc commit 9cc1f3f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

facebook/qsf-tools/qsf-utils.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,21 @@ get_block_item_map <- function(qsf) {
4646

4747

4848
#' Get wave number from qsf filename
49+
#'
50+
#' Wave number as provided in the qsf name should be an integer or a float with
51+
#' one decimal place.
4952
#'
5053
#' @param path_to_qsf
5154
#'
52-
#' @return integer wave number
55+
#' @return (mostly) integer wave number
5356
get_wave <- function(path_to_qsf) {
54-
qsf_name_pattern <- "(.*Wave_)([0-9]*)([.]qsf)$"
57+
qsf_name_pattern <- "(.*Wave_)([0-9]*([.][0-9])?)([.]qsf)$"
5558
if (!grepl(qsf_name_pattern, path_to_qsf)) {
5659
stop("qsf filename should be of the format 'Survey_of_COVID-Like_Illness_-_Wave_XX.qsf'")
5760
}
5861

59-
wave <- as.integer(sub(
60-
"(.*Wave_)([0-9]*)([.]qsf)$",
61-
"\\2",
62-
path_to_qsf)
62+
wave <- as.numeric(
63+
sub(qsf_name_pattern, "\\2", path_to_qsf)
6364
)
6465

6566
return(wave)

0 commit comments

Comments
 (0)