Skip to content

Commit

Permalink
Deploying to gh-pages from @ d118af9 πŸš€
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Jan 7, 2024
1 parent 2988696 commit 01d105e
Show file tree
Hide file tree
Showing 52 changed files with 389 additions and 389 deletions.
2 changes: 1 addition & 1 deletion 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h1>Page not found<a class="anchor" aria-label="anchor" href="#page-not-found"><
<footer class="bg-primary text-light mt-5"><div class="container"><div class="row">

<div class="col-12 col-md-6 mt-3">
<p>"<strong>Advanced R Exercises</strong>" was written by <a class="text-light" href="https://sites.google.com/site/indrajeetspatilmorality/">Indrajeet Patil</a>. It was last built on 2023-12-31.</p>
<p>"<strong>Advanced R Exercises</strong>" was written by <a class="text-light" href="https://sites.google.com/site/indrajeetspatilmorality/">Indrajeet Patil</a>. It was last built on 2024-01-07.</p>
</div>

<div class="col-12 col-md-6 mt-3">
Expand Down
4 changes: 2 additions & 2 deletions Conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ rlang::catch_cnd
#> return(NULL)
#> })))
#> }
#> <bytecode: 0x564fa21357a8>
#> <bytecode: 0x55f2c19fa068>
#> <environment: namespace:rlang>
```

Expand Down Expand Up @@ -691,7 +691,7 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2023-12-31
#> date 2024-01-07
#> pandoc 3.1.8 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
Expand Down
2 changes: 1 addition & 1 deletion Control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2023-12-31
#> date 2024-01-07
#> pandoc 3.1.8 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
Expand Down
16 changes: 8 additions & 8 deletions Environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library(rlang)
e <- env()
e$loop <- e
env_print(e)
#> <environment: 0x558a72b692e8>
#> <environment: 0x5592b255c2e8>
#> Parent: <environment: global>
#> Bindings:
#> β€’ loop: <env>
Expand All @@ -51,8 +51,8 @@ The binding `loop` should have the same memory address as the environment `e`:

```r
lobstr::ref(e$loop)
#> β–ˆ [1:0x558a72b692e8] <env>
#> └─loop = [1:0x558a72b692e8]
#> β–ˆ [1:0x5592b255c2e8] <env>
#> └─loop = [1:0x5592b255c2e8]
```

**Q3.** Create a pair of environments as illustrated by this picture.
Expand All @@ -71,9 +71,9 @@ e2$deloop <- e1

# following should be the same
lobstr::obj_addrs(list(e1, e2$deloop))
#> [1] "0x558a751c8be8" "0x558a751c8be8"
#> [1] "0x5592b4bbb1e8" "0x5592b4bbb1e8"
lobstr::obj_addrs(list(e2, e1$loop))
#> [1] "0x558a75216348" "0x558a75216348"
#> [1] "0x5592b4c08948" "0x5592b4c08948"
```

**Q4.** Explain why `e[[1]]` and `e[c("a", "b")]` don't make sense when `e` is an environment.
Expand Down Expand Up @@ -300,7 +300,7 @@ fget("mean", inherits = FALSE)
fget("mean", inherits = TRUE)
#> function (x, ...)
#> UseMethod("mean")
#> <bytecode: 0x558a7059e5a8>
#> <bytecode: 0x5592aff915a8>
#> <environment: namespace:base>

mean <- 5
Expand Down Expand Up @@ -506,7 +506,7 @@ rlang::caller_env
#> {
#> parent.frame(n + 1)
#> }
#> <bytecode: 0x558a710bd8d0>
#> <bytecode: 0x5592b0ab08d0>
#> <environment: namespace:rlang>
```

Expand Down Expand Up @@ -559,7 +559,7 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2023-12-31
#> date 2024-01-07
#> pandoc 3.1.8 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
Expand Down
12 changes: 6 additions & 6 deletions Evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ withr::with_tempdir(
foo()
}
)
#> <environment: 0x56269fbe7e18>
#> <environment: 0x564fa1bed6a8>
#> Parent: <environment: global>
```

Expand Down Expand Up @@ -250,17 +250,17 @@ q1 <- new_quosure(expr(x), env(x = 1))
q1
#> <quosure>
#> expr: ^x
#> env: 0x56269fa39110
#> env: 0x564fa1a3e9a0
q2 <- new_quosure(expr(x + !!q1), env(x = 10))
q2
#> <quosure>
#> expr: ^x + (^x)
#> env: 0x5626a008bd48
#> env: 0x564fa20915d8
q3 <- new_quosure(expr(x + !!q2), env(x = 100))
q3
#> <quosure>
#> expr: ^x + (^x + (^x))
#> env: 0x5626a034a820
#> env: 0x564fa23500b0
```

**A1.** Correctly predicted πŸ˜‰
Expand Down Expand Up @@ -298,7 +298,7 @@ enenv(x)

foo <- function(x) enenv(x)
foo()
#> <environment: 0x5626a12b70c8>
#> <environment: 0x564fa32bc708>
```

---
Expand Down Expand Up @@ -674,7 +674,7 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2023-12-31
#> date 2024-01-07
#> pandoc 3.1.8 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
Expand Down
4 changes: 2 additions & 2 deletions Expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ call_standardise(quote(mean(x = 1:10, , TRUE)))
mean
#> function (x, ...)
#> UseMethod("mean")
#> <bytecode: 0x55d34a3275a8>
#> <bytecode: 0x562fc13895a8>
#> <environment: namespace:base>
```

Expand Down Expand Up @@ -993,7 +993,7 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2023-12-31
#> date 2024-01-07
#> pandoc 3.1.8 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
Expand Down
50 changes: 25 additions & 25 deletions Function-factories.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ library(ggplot2, warn.conflicts = FALSE)
force
#> function (x)
#> x
#> <bytecode: 0x556cfd712ab0>
#> <bytecode: 0x56479c5e3ab0>
#> <environment: namespace:base>
```

Expand All @@ -47,8 +47,8 @@ f <- approxfun(x, y)
f
#> function (v)
#> .approxfun(x, y, v, method, yleft, yright, f, na.rm)
#> <bytecode: 0x556d01983cb0>
#> <environment: 0x556d01982ba0>
#> <bytecode: 0x5647a0854cb0>
#> <environment: 0x5647a0853ba0>
f(x)
#> [1] -0.7786629 -0.3894764 -2.0337983 -0.9823731 0.2478901
#> [6] -2.1038646 -0.3814180 2.0749198 1.0271384 0.4730142
Expand Down Expand Up @@ -212,15 +212,15 @@ new_counter3()
#> i <- i + 1
#> i
#> }
#> <environment: 0x556d01b28e68>
#> <environment: 0x5647a09f9e68>

new_counter3()
#> function() {
#> i <- i + 1
#> i
#> }
#> <bytecode: 0x556d01ced600>
#> <environment: 0x556d01ba0c80>
#> <bytecode: 0x5647a0bbe600>
#> <environment: 0x5647a0a71c80>
```

---
Expand Down Expand Up @@ -258,7 +258,7 @@ ggplot2::label_bquote
#> }
#> structure(fun, class = "labeller")
#> }
#> <bytecode: 0x556d01e7f0b0>
#> <bytecode: 0x5647a0d500b0>
#> <environment: namespace:ggplot2>
```

Expand All @@ -281,7 +281,7 @@ scales::number_format
#> scale_cut = scale_cut, trim = trim, ...)
#> }
#> }
#> <bytecode: 0x556d020cfbc8>
#> <bytecode: 0x5647a0fa0bc8>
#> <environment: namespace:scales>
```

Expand Down Expand Up @@ -377,7 +377,7 @@ Let's have a look at one example with each:
```r
boxcox2(1)
#> function(x) (x^lambda - 1) / lambda
#> <environment: 0x556cfdac76a0>
#> <environment: 0x56479c998358>

boxcox3(mtcars$wt)
#> function(lambda) {
Expand All @@ -387,7 +387,7 @@ boxcox3(mtcars$wt)
#> (x^lambda - 1) / lambda
#> }
#> }
#> <environment: 0x556cfefae4d0>
#> <environment: 0x56479de7f188>
```

As can be seen:
Expand Down Expand Up @@ -420,7 +420,7 @@ boot_permute(mtcars, "mpg")
#> col <- df[[var]]
#> col[sample(n, replace = TRUE)]
#> }
#> <environment: 0x556d00bef850>
#> <environment: 0x56479fac0b28>
```

This is why we don't need to worry about a copy being made because the `df` in the function environment points to the memory address of the data frame. We can confirm this by comparing their memory addresses:
Expand All @@ -429,7 +429,7 @@ This is why we don't need to worry about a copy being made because the `df` in t
```r
boot_permute_env <- rlang::fn_env(boot_permute(mtcars, "mpg"))
rlang::env_print(boot_permute_env)
#> <environment: 0x556d0181e450>
#> <environment: 0x5647a06ef728>
#> Parent: <environment: global>
#> Bindings:
#> β€’ n: <int>
Expand Down Expand Up @@ -488,8 +488,8 @@ bench::mark(
#> # A tibble: 2 Γ— 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 LL1 27.5Β΅s 29.3Β΅s 33174. 12.9KB 43.2
#> 2 LL2 14.6Β΅s 15.3Β΅s 62143. 0B 49.8
#> 1 LL1 28.3Β΅s 30.2Β΅s 31979. 12.9KB 41.6
#> 2 LL2 14.6Β΅s 15.7Β΅s 60147. 0B 48.2
```

As can be seen, the second version is much faster than the first version.
Expand All @@ -515,16 +515,16 @@ generate_ll_benches <- function(n) {
#> # A tibble: 10 Γ— 5
#> length expression min median `itr/sec`
#> <dbl> <bch:expr> <bch:tm> <bch:tm> <dbl>
#> 1 10 LL1 38.9Β΅s 40.9Β΅s 23209.
#> 2 10 LL2 17.2Β΅s 18Β΅s 54710.
#> 3 20 LL1 42.1Β΅s 44Β΅s 22427.
#> 4 20 LL2 16.9Β΅s 17.7Β΅s 55356.
#> 5 50 LL1 46.2Β΅s 47.9Β΅s 20558.
#> 6 50 LL2 16.2Β΅s 17.2Β΅s 57361.
#> 7 100 LL1 61.9Β΅s 63.6Β΅s 15410.
#> 8 100 LL2 17.6Β΅s 18.4Β΅s 53603.
#> 9 1000 LL1 854.3Β΅s 872.3Β΅s 1092.
#> 10 1000 LL2 54.6Β΅s 55.9Β΅s 17653.
#> 1 10 LL1 39.9Β΅s 42.1Β΅s 22543.
#> 2 10 LL2 17.3Β΅s 18.3Β΅s 53968.
#> 3 20 LL1 43Β΅s 44.6Β΅s 22159.
#> 4 20 LL2 17.1Β΅s 18Β΅s 54815.
#> 5 50 LL1 46.8Β΅s 48.3Β΅s 20374.
#> 6 50 LL2 16.3Β΅s 17.4Β΅s 56753.
#> 7 100 LL1 62.4Β΅s 64.1Β΅s 15369.
#> 8 100 LL2 17.6Β΅s 18.4Β΅s 53652.
#> 9 1000 LL1 857.4Β΅s 965Β΅s 1081.
#> 10 1000 LL2 54.6Β΅s 56.2Β΅s 17530.

ggplot(
df_bench,
Expand Down Expand Up @@ -648,7 +648,7 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2023-12-31
#> date 2024-01-07
#> pandoc 3.1.8 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
Expand Down
Binary file modified Function-factories_files/figure-html/Function-factories-28-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions Function-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ possibly
#> })
#> }
#> }
#> <bytecode: 0x55d90290c0b8>
#> <bytecode: 0x55d5181c6328>
#> <environment: namespace:purrr>
```

Expand All @@ -120,7 +120,7 @@ safely
#> check_bool(quiet)
#> function(...) capture_error(.f(...), otherwise, quiet)
#> }
#> <bytecode: 0x55d902aa9948>
#> <bytecode: 0x55d518363bb8>
#> <environment: namespace:purrr>

purrr:::capture_error
Expand All @@ -132,7 +132,7 @@ purrr:::capture_error
#> list(result = otherwise, error = e)
#> })
#> }
#> <bytecode: 0x55d902b04180>
#> <bytecode: 0x55d5183be3f0>
#> <environment: namespace:purrr>
```

Expand Down Expand Up @@ -281,10 +281,10 @@ withr::with_tempfile("logfile", code = {

cat(readLines(logfile), sep = "\n")
})
#> Function created at: 2023-12-31 00:43:08.117083
#> Function called at: 2023-12-31 00:43:13.123988
#> Function called at: 2023-12-31 00:43:18.129344
#> Function called at: 2023-12-31 00:43:26.137767
#> Function created at: 2024-01-07 00:44:00.426587
#> Function called at: 2024-01-07 00:44:05.433612
#> Function called at: 2024-01-07 00:44:10.439013
#> Function called at: 2024-01-07 00:44:18.447574
```

---
Expand Down Expand Up @@ -333,7 +333,7 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2023-12-31
#> date 2024-01-07
#> pandoc 3.1.8 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
Expand Down
Loading

0 comments on commit 01d105e

Please sign in to comment.