diff --git a/DESCRIPTION b/DESCRIPTION index b2a1383..4c7659e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: phonfieldwork Type: Package Title: Linguistic Phonetic Fieldwork Tools -Version: 0.0.15 +Version: 0.0.16 Depends: R (>= 3.5.0) Imports: tuneR, diff --git a/NEWS.md b/NEWS.md index 8bfaa1f..b2b3451 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,11 @@ +# phonfieldwork 0.0.16 + +- small fix + # phonfieldwork 0.0.15 - small fix in `df_to_tier` of cases with non-equal time_end and time_start values in the dataframe - # phonfieldwork 0.0.14 - small fix diff --git a/R/df_to_tier.R b/R/df_to_tier.R index 7ef6235..1ff3be2 100644 --- a/R/df_to_tier.R +++ b/R/df_to_tier.R @@ -41,6 +41,7 @@ df_to_tier <- function(df, textgrid, tier_name = "", overwrite = TRUE) { n_tiers <- as.numeric(gsub("\\D", "", tg[7])) tg[7] <- paste0("size = ", n_tiers + 1, " ") + textgrid_duration <- gsub("[a-z\\=\\s]", "", tg[5]) |> as.double() if (!(FALSE %in% (df$time_start == df$time_end))) { df <- df[, -which(names(df) %in% "time_end")] @@ -48,16 +49,22 @@ df_to_tier <- function(df, textgrid, tier_name = "", overwrite = TRUE) { if (TRUE %in% (df$time_end[-nrow(df)] != df$time_start[-1])){ wrong_time_end <- which(df$time_end[-nrow(df)] != df$time_start[-1]) - silence <- lapply(wrong_time_end, function(i){ + silence <- lapply(rev(wrong_time_end), function(i){ df <<- rbind(df[c(1:i),], data.frame(time_start = df$time_end[i], time_end = df$time_start[i+1], content = ""), - df[-c(1:i),] - ) + df[-c(1:i),]) }) } + if(df$time_end[nrow(df)] != textgrid_duration){ + df <- rbind(df, + data.frame(time_start = df$time_end[nrow(df)], + time_end = textgrid_duration, + content = "")) + } + tier_class <- ifelse("time_end" %in% names(df), ' class = "IntervalTier" ', ' class = "TextTier" '