The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

tikatuwq: basic workflow

tikatuwq authors

Load package and demo dataset

library(tikatuwq)

# Try to make wq_demo available even when the package
# cannot be temporarily reinstalled during pkgdown build.
ok <- FALSE
try({
  utils::data("wq_demo", package = "tikatuwq", envir = environment())
  ok <- exists("wq_demo", inherits = FALSE)
}, silent = TRUE)

if (!ok) {
  # Fallback: read example CSV shipped with the package
  csv <- system.file("extdata", "exemplo_chamagunga.csv", package = "tikatuwq")
  if (nzchar(csv)) {
    wq_demo <- read_wq(csv)
    ok <- TRUE
  }
}

if (!ok) {
  # Last resort: small synthetic dataset (schema-compatible)
  set.seed(1)
  wq_demo <- data.frame(
    data = as.Date("2025-01-01") + 0:9,
    rio = "Demo",
    ponto = paste0("P", seq_len(10)),
    turbidez = runif(10, 1, 50),
    od = runif(10, 5, 9),
    pH = runif(10, 6.5, 8.5),
    temperatura = runif(10, 20, 28),
    condutividade = runif(10, 50, 300),
    stringsAsFactors = FALSE
  )
}

# Coerce common numeric columns defensively (some example files may carry strings)
num_candidates <- c(
  "turbidez","od","pH","temperatura","condutividade",
  "dbo","dbo5","nitrato","fosforo","amonia",
  "coliformes","coliformes_totais","coliformes_termotolerantes"
)
for (nm in intersect(num_candidates, names(wq_demo))) {
  suppressWarnings({ wq_demo[[nm]] <- as.numeric(wq_demo[[nm]]) })
}

head(wq_demo)
#>   ponto       data   ph   od turbidez  dbo coliformes p_total nt_total
#> 1    P1 2024-06-07 7.08 5.33     63.8 5.38        331   0.080     1.30
#> 2    P1 2024-06-27 6.79 8.29     35.7 1.46         98   0.348     3.69
#> 3    P1 2024-01-14 8.43 4.23     60.6 1.22       3712   0.313     4.25
#> 4    P1 2024-07-13 8.30 6.21     50.7 4.09        200   0.447     2.54
#> 5    P1 2024-06-18 7.88 7.99     57.1 2.39         66   0.340     2.00
#> 6    P2 2024-02-19 8.09 4.61      1.0 4.11       3930   0.371     1.31
#>   temperatura tds
#> 1        23.0 249
#> 2        21.2 329
#> 3        25.6 480
#> 4        20.2 731
#> 5        28.4 201
#> 6        27.0 724

Compute IQA and check CONAMA compliance

ok_iqa <- TRUE
df <- tryCatch({
  wq_demo |>
    validate_wq() |>
    iqa(na_rm = TRUE)
}, error = function(e) {
  ok_iqa <<- FALSE
  message("iqa() failed in vignette build: ", conditionMessage(e))
  wq_demo |>
    validate_wq()
})

conf <- tryCatch({
  conama_check(df, classe = "2")
}, error = function(e) {
  message("conama_check() failed in vignette build: ", conditionMessage(e))
  NULL
})

if (!is.null(conf)) head(conf)
#>   ponto       data   ph   od turbidez  dbo coliformes p_total nt_total
#> 1    P1 2024-06-07 7.08 5.33     63.8 5.38        331   0.080     1.30
#> 2    P1 2024-06-27 6.79 8.29     35.7 1.46         98   0.348     3.69
#> 3    P1 2024-01-14 8.43 4.23     60.6 1.22       3712   0.313     4.25
#> 4    P1 2024-07-13 8.30 6.21     50.7 4.09        200   0.447     2.54
#> 5    P1 2024-06-18 7.88 7.99     57.1 2.39         66   0.340     2.00
#> 6    P2 2024-02-19 8.09 4.61      1.0 4.11       3930   0.371     1.31
#>   temperatura tds      IQA ph_ok ph_status ph__lim_min ph__lim_max ph__delta
#> 1        23.0 249 8.169772  TRUE        ok           6           9         0
#> 2        21.2 329 8.772986  TRUE        ok           6           9         0
#> 3        25.6 480 7.195704  TRUE        ok           6           9         0
#> 4        20.2 731 8.022852  TRUE        ok           6           9         0
#> 5        28.4 201 8.789324  TRUE        ok           6           9         0
#> 6        27.0 724 7.422467  TRUE        ok           6           9         0
#>   od_ok        od_status od__lim_min od__lim_max od__delta turbidez_ok
#> 1  TRUE               ok           5          NA      0.00        TRUE
#> 2  TRUE               ok           5          NA      0.00        TRUE
#> 3 FALSE abaixo_do_minimo           5          NA     -0.77        TRUE
#> 4  TRUE               ok           5          NA      0.00        TRUE
#> 5  TRUE               ok           5          NA      0.00        TRUE
#> 6 FALSE abaixo_do_minimo           5          NA     -0.39        TRUE
#>   turbidez_status turbidez__lim_min turbidez__lim_max turbidez__delta dbo_ok
#> 1              ok                NA               100               0  FALSE
#> 2              ok                NA               100               0   TRUE
#> 3              ok                NA               100               0   TRUE
#> 4              ok                NA               100               0   TRUE
#> 5              ok                NA               100               0   TRUE
#> 6              ok                NA               100               0   TRUE
#>        dbo_status dbo__lim_min dbo__lim_max dbo__delta coliformes_ok
#> 1 acima_do_maximo           NA            5       0.38          TRUE
#> 2              ok           NA            5       0.00          TRUE
#> 3              ok           NA            5       0.00         FALSE
#> 4              ok           NA            5       0.00          TRUE
#> 5              ok           NA            5       0.00          TRUE
#> 6              ok           NA            5       0.00         FALSE
#>   coliformes_status coliformes__lim_min coliformes__lim_max coliformes__delta
#> 1                ok                  NA                1000                 0
#> 2                ok                  NA                1000                 0
#> 3   acima_do_maximo                  NA                1000              2712
#> 4                ok                  NA                1000                 0
#> 5                ok                  NA                1000                 0
#> 6   acima_do_maximo                  NA                1000              2930
#>   p_total_ok  p_total_status p_total__lim_min p_total__lim_max p_total__delta
#> 1      FALSE acima_do_maximo               NA             0.05          0.030
#> 2      FALSE acima_do_maximo               NA             0.05          0.298
#> 3      FALSE acima_do_maximo               NA             0.05          0.263
#> 4      FALSE acima_do_maximo               NA             0.05          0.397
#> 5      FALSE acima_do_maximo               NA             0.05          0.290
#> 6      FALSE acima_do_maximo               NA             0.05          0.321

Summaries and plots

if (isTRUE(ok_iqa)) {
  plot_iqa(df)
}

conf_long <- tryCatch(conama_summary(df, classe = "2"), error = function(e) NULL)
if (!is.null(conf_long)) head(conf_long)
#> # A tibble: 6 × 7
#>   parametro valor lim_min lim_max status ok    delta
#>   <chr>     <dbl>   <dbl>   <dbl> <chr>  <lgl> <dbl>
#> 1 ph         7.08       6       9 ok     TRUE      0
#> 2 ph         6.79       6       9 ok     TRUE      0
#> 3 ph         8.43       6       9 ok     TRUE      0
#> 4 ph         8.3        6       9 ok     TRUE      0
#> 5 ph         7.88       6       9 ok     TRUE      0
#> 6 ph         8.09       6       9 ok     TRUE      0

Render a report (writes to a temporary directory)

# Avoid running nested rendering during vignette build on CRAN
out_file <- render_report(df)
out_file

Interactive maps (plot_map)

if (eval_interactive) {
  # Minimal example dataset with coordinates
  df_map <- data.frame(
    rio = c("Buranhem","Chamagunga"),
    ponto = c("P1","P2"),
    data = as.Date(c("2025-09-20","2025-09-21")),
    latitude  = c(-16.435, -16.498),
    longitude = c(-39.062, -39.080),
    iqa = c(72, 58)
  )

  plot_map(
    df_map,
    popup_cols = c("rio","ponto","data","iqa"),
    color_by = "iqa"
  )
}
if (eval_interactive) {
  plot_map(
    df_map,
    popup_cols = c("rio","ponto","data","iqa"),
    cluster = FALSE,
    tiles = "CartoDB.Positron"
  )
}

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.