Skip to content

Commit

Permalink
Deploying to gh-pages from @ 5286607 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Jun 30, 2024
1 parent e53081a commit 31f4a47
Show file tree
Hide file tree
Showing 52 changed files with 484 additions and 484 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 2024-06-23.</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-06-30.</p>
</div>

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

Expand Down Expand Up @@ -718,8 +718,8 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2024-06-23
#> pandoc 3.2 @ /opt/hostedtoolcache/pandoc/3.2/x64/ (via rmarkdown)
#> date 2024-06-30
#> pandoc 3.2.1 @ /opt/hostedtoolcache/pandoc/3.2.1/x64/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
#> package * version date (UTC) lib source
Expand All @@ -732,7 +732,7 @@ sessioninfo::session_info(include_base = TRUE)
#> compiler 4.4.1 2024-06-14 [3] local
#> datasets * 4.4.1 2024-06-14 [3] local
#> desc 1.4.3 2023-12-10 [1] RSPM
#> digest 0.6.35 2024-03-11 [1] RSPM
#> digest 0.6.36 2024-06-23 [1] RSPM
#> downlit 0.4.4 2024-06-10 [1] RSPM
#> dplyr 1.1.4 2023-11-17 [1] RSPM
#> evaluate 0.24.0 2024-06-10 [1] RSPM
Expand All @@ -753,7 +753,7 @@ sessioninfo::session_info(include_base = TRUE)
#> methods * 4.4.1 2024-06-14 [3] local
#> pillar 1.9.0 2023-03-22 [1] RSPM
#> pkgconfig 2.0.3 2019-09-22 [1] RSPM
#> pkgload 1.3.4 2024-01-16 [1] RSPM
#> pkgload 1.4.0 2024-06-28 [1] RSPM
#> R6 2.5.1 2021-08-19 [1] RSPM
#> rlang * 1.1.4 2024-06-04 [1] RSPM
#> rmarkdown 2.27 2024-05-17 [1] RSPM
Expand Down
6 changes: 3 additions & 3 deletions Control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2024-06-23
#> pandoc 3.2 @ /opt/hostedtoolcache/pandoc/3.2/x64/ (via rmarkdown)
#> date 2024-06-30
#> pandoc 3.2.1 @ /opt/hostedtoolcache/pandoc/3.2.1/x64/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
#> package * version date (UTC) lib source
Expand All @@ -288,7 +288,7 @@ sessioninfo::session_info(include_base = TRUE)
#> cli 3.6.3 2024-06-21 [1] RSPM
#> compiler 4.4.1 2024-06-14 [3] local
#> datasets * 4.4.1 2024-06-14 [3] local
#> digest 0.6.35 2024-03-11 [1] RSPM
#> digest 0.6.36 2024-06-23 [1] RSPM
#> downlit 0.4.4 2024-06-10 [1] RSPM
#> evaluate 0.24.0 2024-06-10 [1] RSPM
#> fastmap 1.2.0 2024-05-15 [1] RSPM
Expand Down
20 changes: 10 additions & 10 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: 0x557bf7fd1ff0>
#> <environment: 0x55b30b93a7c0>
#> 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:0x557bf7fd1ff0] <env>
#> └─loop = [1:0x557bf7fd1ff0]
#> █ [1:0x55b30b93a7c0] <env>
#> └─loop = [1:0x55b30b93a7c0]
```

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

# following should be the same
lobstr::obj_addrs(list(e1, e2$deloop))
#> [1] "0x557bf83ad810" "0x557bf83ad810"
#> [1] "0x55b30c8d1370" "0x55b30c8d1370"
```

``` r
lobstr::obj_addrs(list(e2, e1$loop))
#> [1] "0x557bf822b778" "0x557bf822b778"
#> [1] "0x55b30c85b5c0" "0x55b30c85b5c0"
```

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

Expand Down Expand Up @@ -569,7 +569,7 @@ rlang::caller_env
#> {
#> parent.frame(n + 1)
#> }
#> <bytecode: 0x557bf7b9b730>
#> <bytecode: 0x55b30a60e558>
#> <environment: namespace:rlang>
```

Expand Down Expand Up @@ -625,8 +625,8 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2024-06-23
#> pandoc 3.2 @ /opt/hostedtoolcache/pandoc/3.2/x64/ (via rmarkdown)
#> date 2024-06-30
#> pandoc 3.2.1 @ /opt/hostedtoolcache/pandoc/3.2.1/x64/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
#> package * version date (UTC) lib source
Expand All @@ -638,7 +638,7 @@ sessioninfo::session_info(include_base = TRUE)
#> compiler 4.4.1 2024-06-14 [3] local
#> crayon 1.5.3 2024-06-20 [1] RSPM
#> datasets * 4.4.1 2024-06-14 [3] local
#> digest 0.6.35 2024-03-11 [1] RSPM
#> digest 0.6.36 2024-06-23 [1] RSPM
#> downlit 0.4.4 2024-06-10 [1] RSPM
#> dplyr 1.1.4 2023-11-17 [1] RSPM
#> evaluate 0.24.0 2024-06-10 [1] RSPM
Expand Down
16 changes: 8 additions & 8 deletions Evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ withr::with_tempdir(
foo()
}
)
#> <environment: 0x564b8bb5cd40>
#> <environment: 0x55bdbe8e05c8>
#> Parent: <environment: global>
```

Expand Down Expand Up @@ -268,23 +268,23 @@ q1 <- new_quosure(expr(x), env(x = 1))
q1
#> <quosure>
#> expr: ^x
#> env: 0x564b8c609f48
#> env: 0x55bdc0255228
```

``` r
q2 <- new_quosure(expr(x + !!q1), env(x = 10))
q2
#> <quosure>
#> expr: ^x + (^x)
#> env: 0x564b8ccf2150
#> env: 0x55bdbe8f0410
```

``` r
q3 <- new_quosure(expr(x + !!q2), env(x = 100))
q3
#> <quosure>
#> expr: ^x + (^x + (^x))
#> env: 0x564b8da4fc70
#> env: 0x55bdbce0d408
```

**A1.** Correctly predicted 😉
Expand Down Expand Up @@ -331,7 +331,7 @@ enenv(x)

foo <- function(x) enenv(x)
foo()
#> <environment: 0x564b8e59e3a8>
#> <environment: 0x55bdbeeb27f0>
```

---
Expand Down Expand Up @@ -722,8 +722,8 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2024-06-23
#> pandoc 3.2 @ /opt/hostedtoolcache/pandoc/3.2/x64/ (via rmarkdown)
#> date 2024-06-30
#> pandoc 3.2.1 @ /opt/hostedtoolcache/pandoc/3.2.1/x64/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
#> package * version date (UTC) lib source
Expand All @@ -734,7 +734,7 @@ sessioninfo::session_info(include_base = TRUE)
#> cli 3.6.3 2024-06-21 [1] RSPM
#> compiler 4.4.1 2024-06-14 [3] local
#> datasets * 4.4.1 2024-06-14 [3] local
#> digest 0.6.35 2024-03-11 [1] RSPM
#> digest 0.6.36 2024-06-23 [1] RSPM
#> downlit 0.4.4 2024-06-10 [1] RSPM
#> evaluate 0.24.0 2024-06-10 [1] RSPM
#> fansi 1.0.6 2023-12-08 [1] RSPM
Expand Down
8 changes: 4 additions & 4 deletions Expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ call_standardise(quote(mean(x = 1:10, , TRUE)))
mean
#> function (x, ...)
#> UseMethod("mean")
#> <bytecode: 0x561cab8d7658>
#> <bytecode: 0x55a379f32628>
#> <environment: namespace:base>
```

Expand Down Expand Up @@ -1137,8 +1137,8 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2024-06-23
#> pandoc 3.2 @ /opt/hostedtoolcache/pandoc/3.2/x64/ (via rmarkdown)
#> date 2024-06-30
#> pandoc 3.2.1 @ /opt/hostedtoolcache/pandoc/3.2.1/x64/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
#> package * version date (UTC) lib source
Expand All @@ -1150,7 +1150,7 @@ sessioninfo::session_info(include_base = TRUE)
#> compiler 4.4.1 2024-06-14 [3] local
#> crayon 1.5.3 2024-06-20 [1] RSPM
#> datasets * 4.4.1 2024-06-14 [3] local
#> digest 0.6.35 2024-03-11 [1] RSPM
#> digest 0.6.36 2024-06-23 [1] RSPM
#> downlit 0.4.4 2024-06-10 [1] RSPM
#> evaluate 0.24.0 2024-06-10 [1] RSPM
#> fansi 1.0.6 2023-12-08 [1] RSPM
Expand Down
54 changes: 27 additions & 27 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: 0x55a460dfae10>
#> <bytecode: 0x557868c87e10>
#> <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: 0x55a46697a708>
#> <environment: 0x55a466979dd8>
#> <bytecode: 0x55786d6e4620>
#> <environment: 0x55786d6e3cf0>
```

``` r
Expand Down Expand Up @@ -233,7 +233,7 @@ new_counter3()
#> i <- i + 1
#> i
#> }
#> <environment: 0x55a4669664c0>
#> <environment: 0x55786d5d5940>
```

``` r
Expand All @@ -243,8 +243,8 @@ new_counter3()
#> i <- i + 1
#> i
#> }
#> <bytecode: 0x55a466c173f0>
#> <environment: 0x55a4669f7cc0>
#> <bytecode: 0x55786d76fd80>
#> <environment: 0x55786d649c98>
```

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

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

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

``` r
Expand All @@ -414,7 +414,7 @@ boxcox3(mtcars$wt)
#> (x^lambda - 1) / lambda
#> }
#> }
#> <environment: 0x55a46602d678>
#> <environment: 0x55786bde8f00>
```

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

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 @@ -456,7 +456,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: 0x55a466f89408>
#> <environment: 0x55786cbe3be8>
#> Parent: <environment: global>
#> Bindings:
#> • n: <int>
Expand Down Expand Up @@ -521,8 +521,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 28.8µs 30.7µs 31613. 12.8KB 41.1
#> 2 LL2 15.5µs 16.6µs 57581. 0B 40.3
#> 1 LL1 29µs 31.1µs 31435. 12.8KB 37.8
#> 2 LL2 15.6µs 16.6µs 57061. 0B 34.3
```

As can be seen, the second version is much faster than the first version.
Expand All @@ -548,16 +548,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 40.5µs 42.4µs 22296.
#> 2 10 LL2 18.5µs 19.3µs 50861.
#> 3 20 LL1 43.2µs 44.7µs 22050.
#> 4 20 LL2 17.9µs 18.6µs 53051.
#> 5 50 LL1 47.6µs 48.9µs 20126.
#> 6 50 LL2 17.1µs 17.8µs 55451.
#> 7 100 LL1 63.2µs 65.4µs 14892.
#> 8 100 LL2 18.4µs 19.1µs 51570.
#> 9 1000 LL1 856µs 943.9µs 1087.
#> 10 1000 LL2 56.9µs 58.2µs 16946.
#> 1 10 LL1 41µs 43.4µs 22476.
#> 2 10 LL2 18.8µs 19.9µs 48859.
#> 3 20 LL1 42.7µs 45.3µs 20575.
#> 4 20 LL2 18µs 18.8µs 52000.
#> 5 50 LL1 47.6µs 49.7µs 19793.
#> 6 50 LL2 17.2µs 18.1µs 54489.
#> 7 100 LL1 62.9µs 65µs 15042.
#> 8 100 LL2 18.3µs 19.2µs 50495.
#> 9 1000 LL1 859.2µs 966.7µs 1051.
#> 10 1000 LL2 56.8µs 58.9µs 16747.
```

``` r
Expand Down Expand Up @@ -714,8 +714,8 @@ sessioninfo::session_info(include_base = TRUE)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2024-06-23
#> pandoc 3.2 @ /opt/hostedtoolcache/pandoc/3.2/x64/ (via rmarkdown)
#> date 2024-06-30
#> pandoc 3.2.1 @ /opt/hostedtoolcache/pandoc/3.2.1/x64/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
#> package * version date (UTC) lib source
Expand All @@ -728,7 +728,7 @@ sessioninfo::session_info(include_base = TRUE)
#> colorspace 2.1-0 2023-01-23 [1] RSPM
#> compiler 4.4.1 2024-06-14 [3] local
#> datasets * 4.4.1 2024-06-14 [3] local
#> digest 0.6.35 2024-03-11 [1] RSPM
#> digest 0.6.36 2024-06-23 [1] RSPM
#> downlit 0.4.4 2024-06-10 [1] RSPM
#> dplyr 1.1.4 2023-11-17 [1] RSPM
#> evaluate 0.24.0 2024-06-10 [1] RSPM
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.
Loading

0 comments on commit 31f4a47

Please sign in to comment.