## ----setup--------------------------------------------------------------------
library(ggsql)


## VISUALIZE species AS x FROM ggsql:penguins
## DRAW bar

## SELECT COUNT(*) AS count, species FROM ggsql:penguins
## GROUP BY species

## -----------------------------------------------------------------------------
gapminder_2002 <- gapminder::gapminder[gapminder::gapminder$year == 2002, ]


## VISUALIZE gdpPercap AS x, lifeExp AS y FROM r:gapminder_2002
## DRAW point
##   MAPPING continent AS stroke, pop AS size
##   SETTING fill => null
## LABEL
##   title => 'Rendering data from R'

## CREATE VIEW may_airquality AS
## SELECT * FROM ggsql:airquality
## WHERE Month = 5

## CREATE TABLE penguin_count AS
## SELECT COUNT(*) AS number, species FROM ggsql:penguins
## GROUP BY species

## -----------------------------------------------------------------------------
names(sql)

sql$penguin_count


## -----------------------------------------------------------------------------
#| include: false
# ggsql caches builtin datasets (penguins, airquality) as parquet files in
# the OS temp dir (Rust's `env::temp_dir()`, i.e. `$TMPDIR` or `/tmp`) and
# never cleans them up. Remove them so R CMD check doesn't flag them as
# detritus in the temp directory.
tmp_root <- Sys.getenv("TMPDIR", unset = "/tmp")
unlink(file.path(tmp_root, c("airquality.parquet", "penguins.parquet")))

