# Downloads {#sec-downloads}
```{r}
#| label: setup-common-01
#| include: false
source("includes/_common.R")
```
## Run {duckplyr} Commands
```{r}
#| label: setup-duckplyr
library(duckplyr)
db_exec("INSTALL httpfs")
db_exec("LOAD httpfs")
db_exec("INSTALL json")
db_exec("LOAD json")
read_sql_duckdb("SELECT current_setting('memory_limit') AS memlimit")
db_exec("PRAGMA memory_limit = '1GB'")
read_sql_duckdb("SELECT current_setting('memory_limit') AS memlimit")
db_exec("PRAGMA enable_progress_bar = true")
read_sql_duckdb("SELECT current_setting('threads') AS threads")
read_sql_duckdb("SELECT * FROM duckdb_settings()")
```
## Provider Enrollment Sub-Files
```{r}
#| label: enrollees_subfiles
resources <- prop(
public_Dataset("enrollees"),
"resources")
subfiles <- filter(
prop(resources, "files"),
fileType == "csv",
sf_detect(name, "Sub-File")) |>
pull(downloadURL)
basename(subfiles)
```
### Reassignment Sub-File 2024 Q4
```{r}
#| label: reassign_subfile
#| error: true
path <- tempfile("reassign_subfile", fileext = ".csv")
download.file(url = subfiles[1], destfile = path)
dk <- duckplyr::read_csv_duckdb(
path,
prudence = "lavish",
options = list(types = list(c("VARCHAR", "VARCHAR")))) |>
collect()
dk <- fcompute(
dk,
enid_ind = stringi::stri_replace_all_regex(REASGN_BNFT_ENRLMT_ID, "\n", ""),
enid_org = RCV_BNFT_ENRLMT_ID)
fnobs(dk$enid_ind) |>
prettyNum(big.mark = ",")
fndistinct(dk$enid_ind) |>
prettyNum(big.mark = ",")
fndistinct(dk$enid_org) |>
prettyNum(big.mark = ",")
```
### Address Sub-File 2024 Q4
```{r}
#| label: address_subfile
#| error: true
path <- tempfile("address_subfile", fileext = ".csv")
download.file(url = subfiles[2], destfile = path)
dk2 <- read_csv_duckdb(path)
dk2
```
### Secondary Specialty Sub-File 2024 Q4
```{r}
#| label: second_specialty
#| error: true
path <- tempfile("second_specialty", fileext = ".csv")
download.file(url = subfiles[3], destfile = path)
dk3 <- read_csv_duckdb(path)
dk3
```