This vignette shows the end‑to‑end workflow for window‑by‑window QC of large time‑series:
qc_add_flags()
.qc_window_app()
.qc_progress()
.qc_check_plot()
.Flag encoding: 1 = approved
,
0 = unchecked
, -1 = original NA
,
-2 = manual flag
, -3 = unsure
.
"DateTime"
), of class POSIXct.*_qcflag
column).If your time column isn’t POSIXct, the app will show an error. The user should ensure the time column is in proper format and it should not have NA values for time.
# Not run in vignette:
# install.packages("remotes")
# remotes::install_github("anthonydn/qctimeseries", build_vignettes = TRUE)
You can resume from prior work, or start fresh with your own source file.
A .csv example with online data is shown, but any import function (e.g., write_excel) can be used as you set up.
CSV example
ibutton_example <- read.csv(
"https://raw.githubusercontent.com/anthonydn/snowmelt_belowground/master/data/ibuttons.csv")
# subset rows
ibutton_example <- ibutton_example[
ibutton_example$block == 1 &
ibutton_example$treatment == "C.N" &
ibutton_example$tussock == "I",]
# convert datetime to POSIXct
ibutton_example$datetime <- as.POSIXct(ibutton_example$datetime)
# keep only the columns you want
ibutton_example <- ibutton_example[, c("datetime", "temp")]
Add QC flags
Next, add QC flags for the variables you plan to review. Choose
variables using the vars
argument. In this example, there
is only one, but you can choose multiple with
vars = c("var1", "var2")
, etc. The default is all numeric
variables.
qc_progress()
reports per‑variable completion. Use
hide_complete = TRUE
to focus on what remains.
Pick any variable with pct_checked < 100
, then
proceed to the app.
qc_window_app()
opens an interactive plotly graphical
environment. Explanations of plotly graphical controls and the buttons
and navigation are at the bottom of this document, after step 6.
# Change y_col to the variable you are about to check
ibutton_example_qc <- qc_window_app(ibutton_example_qc, time_col = "datetime",
y_col = "temp", # <- EDIT THIS
win_hrs = 10000) # default is 168 (one-week windows)
The app returns the entire data frame when you click Done / Return, with the
temp_qcflag
column updated in place. Thus to record work done in the app, it must be assigned to an object, typically the same as the input data frame, but it could also be a new copy likeibutton_example_qc_copy
Tip: it’s common to work through variables one by one: run the app, finish a variable, save (next section), then move to the next variable.
Warning: When you hide flagged variables, they can still sometimes have flags changed if for example you click “Reset Window → Unchecked” thus it is a good idea to turn them back on to check before you are done working on that window.
Save after each variable and before quitting RStudio, so you can resume later.
Next session, load("ibutton_example_qc.RData")
and
continue.
When you’re done, mask flagged values (set to NA
) and,
if you like, drop flag columns.
Export
CSV (always available):
Excel (requires a writer; two options):
# Option A: writexl (simple)
# install.packages("writexl")
writexl::write_xlsx(df_clean, "cleaned_output.xlsx")
# Option B: openxlsx (more control)
# install.packages("openxlsx")
openxlsx::write.xlsx(df_clean, "cleaned_output.xlsx")
Note: the app removes Plotly’s Autoscale and Reset axes buttons. Use the app’s Home zoom button to restore the default x‑range for the current window.
Button (icon) | What it does |
---|---|
Pan | Drag to move along x/y without changing zoom. |
Zoom | Drag to draw a zoom box on x/y. |
Box Select | Select points in a rectangle (used for flag/approve actions). |
Lasso Select | Freehand select points. |
Zoom In / Zoom Out | Incremental zoom. |
Toggle Spike Lines | Show crosshair spikes on hover. |
Download plot as PNG | Save the current view as a PNG image. |
Selections you make (box/lasso) drive the Flag/Approve Selected buttons.
# 1. Import
data <- read.csv("path/to/input.csv", stringsAsFactors = FALSE)
data$DateTime <- as.POSIXct(data$DateTime, tz = "UTC")
# 2. Add QC flags
vars_to_qc <- c("temp", "hum")
data_qc <- qc_add_flags(data, vars = vars_to_qc)
# 3. Work variable by variable
data_qc <- qc_window_app(data_qc, y_col = "temp", time_col = "DateTime")
save(data_qc, file = "data_qc.RData")
# 4. Progress and optional plot
qc_progress(data_qc, hide_complete = TRUE)
# qc_check_plot(data_qc, "temp", time_col = "DateTime")
# 5. Apply and export
data_clean <- qc_apply_flags(data_qc, drop_flags = TRUE)
write.csv(data_clean, "data_clean.csv", row.names = FALSE)
You can set up a simple QC environment so helpers with little to no R experience can review data by opening an editable R Markdown file and pressing “Run” on each chunk. The only thing they change is the variable name as they move through each variable that needs QC checking.
ibutton_example_qc.RData
; substitute your own file).qc_progress()
.qc_window_app()
.save(...)
so progress persists between
sessions.