---
title: "Telemetry"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{80 Telemetry}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  eval = identical(Sys.getenv("IN_PKGDOWN"), "true") || (getRversion() >= "4.1" && rlang::is_installed(c("conflicted", "nycflights13"))),
  comment = "#>"
)

Sys.setenv(DUCKPLYR_FALLBACK_COLLECT = 0)

options(conflicts.policy = list(warn = FALSE))
```

```{r attach}
library(conflicted)
library(duckplyr)
conflict_prefer("filter", "dplyr")
```

As a drop-in replacement for dplyr, duckplyr will use DuckDB for the operations only if it can, and fall back to dplyr otherwise.
A fallback will not change the correctness of the results, but it may be slower or consume more memory.
We would like to guide our efforts towards improving duckplyr, focusing on the features with the most impact.
To this end, duckplyr collects and uploads telemetry data about fallback situations, but only if permitted by the user:

- Collection is on by default, but can be turned off.
- Uploads are done upon request only.
- There is an option to automatically upload when the package is loaded, this is also opt-in.

The data collected contains:

- The package version
- The error message
- The operation being performed, and the arguments
    - For the input data frames, only the structure is included (column types only), no column names or data

```{r include = FALSE}
Sys.setenv(DUCKPLYR_FALLBACK_COLLECT = "")
Sys.setenv(DUCKPLYR_FALLBACK_AUTOUPLOAD = "")
fallback_purge()
```

Fallback is silent by default, but can be made verbose.

```{r}
Sys.setenv(DUCKPLYR_FALLBACK_INFO = TRUE)
out <-
  flights_df() |>
  summarize(.by = origin, paste(dest, collapse = " "))
```

After logs have been collected, the upload options are displayed the next time the duckplyr package is loaded in an R session.

```{r, echo = FALSE}
duckplyr:::fallback_autoupload()
```

The `fallback_sitrep()` function describes the current configuration and the available options.

See `vignette("fallback")` for details on the fallback mechanism.
