Skip to content

Commit

Permalink
Merge branch 'numbats:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
donotdespair authored May 21, 2024
2 parents cd88e0e + c0f76a6 commit 10ca5f5
Show file tree
Hide file tree
Showing 13 changed files with 1,171 additions and 0 deletions.
88 changes: 88 additions & 0 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,44 @@
],
"Hash": "45f0398006e83a5b10b72a90663d8d8c"
},
"RPostgres": {
"Package": "RPostgres",
"Version": "1.4.6",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"DBI",
"R",
"bit64",
"blob",
"cpp11",
"hms",
"lubridate",
"methods",
"plogr",
"withr"
],
"Hash": "a3ccabc3de4657c14185c91f3e6d4b60"
},
"RSQLite": {
"Package": "RSQLite",
"Version": "2.3.6",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"DBI",
"R",
"bit64",
"blob",
"cpp11",
"memoise",
"methods",
"pkgconfig",
"plogr",
"rlang"
],
"Hash": "ae4a925e0f6bb1b7e5fa96b739c5221a"
},
"Rcpp": {
"Package": "Rcpp",
"Version": "1.0.12",
Expand All @@ -144,6 +182,17 @@
],
"Hash": "5ea2700d21e038ace58269ecdbeb9ec0"
},
"RcppTOML": {
"Package": "RcppTOML",
"Version": "0.2.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"Rcpp"
],
"Hash": "c232938949fcd8126034419cc529333a"
},
"askpass": {
"Package": "askpass",
"Version": "1.2.0",
Expand Down Expand Up @@ -1554,6 +1603,23 @@
],
"Hash": "876c618df5ae610be84356d5d7a5d124"
},
"plogr": {
"Package": "plogr",
"Version": "0.2.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "09eb987710984fc2905c7129c7d85e65"
},
"png": {
"Package": "png",
"Version": "0.1-8",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "bd54ba8a0a5faded999a7aab6e46b374"
},
"praise": {
"Package": "praise",
"Version": "1.0.0",
Expand Down Expand Up @@ -1809,6 +1875,28 @@
],
"Hash": "1425f91b4d5d9a8f25352c44a3d914ed"
},
"reticulate": {
"Package": "reticulate",
"Version": "1.36.1",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"Matrix",
"R",
"Rcpp",
"RcppTOML",
"graphics",
"here",
"jsonlite",
"methods",
"png",
"rappdirs",
"rlang",
"utils",
"withr"
],
"Hash": "e037fb5dc364efdaf616eb6bc05aaca2"
},
"rex": {
"Package": "rex",
"Version": "1.2.1",
Expand Down
Binary file added screenshots/dbplyr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/htmltools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/reticulate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions week10/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@ schedule |>
```{r}
#| output: asis
show_slides(week)
```

## Lab code

Lab code can be downloaded here: [`lab.R`](lab.R)

```{r}
#| output: asis
show_assignments(week)
```
205 changes: 205 additions & 0 deletions week10/lab.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
library(rlang)
parse_expr("seq(1,10, by = 0.5)")
parse_expr("data |> mutate()")
parse_expr("data %>% mutate()")


myseq <- parse_expr("seq(1,10, by = 0.5)")
class(myseq)
new_function(list(), myseq)
eval(myseq)

mycalc <- parse_expr("5 + 3 * 7")

as.list(mycalc)

5 + (3 * 7)


as.list(mycalc[[3]])

as.list(mycalc)
mycalc[[2]] <- 10
mycalc

parse_expr("`+`(5, 3*7)")
parse_expr("`+`(5, `*`(3,7))")

mycalc
lobstr::ast(mycalc)
lobstr::ast(5 + 3 * 7)
as.list(mycalc)


lobstr::ast(
mtcars |>
group_by(cyl) |>
filter(mpg > 0.2) |>
mutate(mpg/wt) |>
ggplot()
)

parse_expr(
"mtcars |>
group_by(cyl) |>
filter(mpg > 0.2) |>
mutate(mpg/wt) |>
ggplot()"
)

lobstr::ast((-2)^2)
(-2)^2

lobstr::ast(!countries %in% c("Australia", "China"))


as.list(myseq)
call2("seq", 1L, 10, by = 0.5)
parse_expr(sprintf("seq(%i,%i, by = %f)", 1L, 10, 0.5))


x / y
x <- expr(3 + 6)
y <- expr(1 + 2)

call2("/", x, y)
parse_expr(sprintf("%s / %s", "3 + 6", "1 + 2"))


with(
list(
`+` = base::`-`,
`-` = base::`+`
),
3 + 8
)

library(rlang)
pkgs <- "rlang"
library(pkgs)

purrr::map(
c("ggplot2", "dplyr", "tidyr"),
library,
character.only = TRUE
)

purrr::map(
c("ggplot2", "dplyr", "tidyr"),
call2, .fn = "library"
) |>
purrr::map(eval)


library("ggplot2")

mtcars |> select(cyl)
cyl

readr::read_csv("data/study.csv")

ggplot(mtcars, aes(mpg, wt)) +
geom_point()

ggplot2:::`+.gg`
mpg
wt

mtcars |>
mutate(wt/hp)


mtcars |>
left_join(mpg, by = c("model" = "car"))

join_by

1 + 1

base::`+`

eval(sym("pi"))
sym("pi")
sym("mpg")
expr(1/pi)
lobstr::ast(1/pi)
quo(1/pi)
eval_tidy(quo(1/pi))

function(expr) {
expr <- enexpr(expr)
}


call2(sym("mutate"), sym("mtcars"), expr(wt/sym("hp")))

"mutate"()

sym("2 * pi")

mtcars |>
mutate(2 * mpg) |>
select("2 * mpg")

expr(2 * pi)
lobstr::ast(2*pi)

quo(2 * pi)


capture_expr <- function(x) {
x <- enquo(x)
pi <- 2.29
eval_tidy(x)
}

capture_expr(2*pi)
# expr(2*pi)

myseq
lobstr::ast(myseq)
lobstr::ast(!!myseq)

expr(!!pi)
expr(1/pi)
expr(1/!!pi)

wt <- rnorm(32)
mtcars |>
summarise(weighted.mean(mpg, !!wt))

cyl <- 4
mtcars |>
filter(cyl == !!cyl)

var_summary(mtcars, cyl)

syms(c("a", "b"))
exprs(a+b, a-b)
quos(a+b, a-b)

var_summaries <- function(data, ...) {
vars <- enquos(...)
.min <- purrr::map(vars, ~ expr(min(!!.)))
names(.min) <- c("a", "b")
.max <- purrr::map(vars, ~ expr(max(!!.)))
data |>
summarise(n = n(), !!!.min, !!!.max)
# summarise(n = n(), a = min(mpg), b = min(wt), !!!.max)
}
mtcars |>
group_by(cyl) |>
var_summaries(mpg, wt)



cyl <- 4
mtcars |>
filter(cyl == !!cyl)
mtcars |>
filter(.data$pi == .env$cyl)

mtcars |>
filter(.data$pi == .env$cyl)

pi
1 change: 1 addition & 0 deletions week10/slides.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ Do the following functions use standard evaluation or NSE?
* `a + b * c`
* `mtcars |> select(cyl)`
* `read_csv("data/study.csv")`
* `ggplot() + geom_line()`
* `mtcars |> mutate(wt/hp)`
* `with(mtcars, wt/hp)`
:::
Expand Down
Binary file added week11/earth.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions week11/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,14 @@ schedule |>
```{r}
#| output: asis
show_slides(week)
```


## Lab code

Lab code can be downloaded here: [`lab.R`](lab.R)

```{r}
#| output: asis
show_assignments(week)
```
Loading

0 comments on commit 10ca5f5

Please sign in to comment.