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 Dec 31, 2023
1 parent 0e0e92a commit 2988696
Show file tree
Hide file tree
Showing 52 changed files with 385 additions and 385 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-24.</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 2023-12-31.</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: 0x55774d431098>
#> <bytecode: 0x564fa21357a8>
#> <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-24
#> date 2023-12-31
#> 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-24
#> date 2023-12-31
#> 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: 0x562e64f1d6d8>
#> <environment: 0x558a72b692e8>
#> 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:0x562e64f1d6d8] <env>
#> └─loop = [1:0x562e64f1d6d8]
#> β–ˆ [1:0x558a72b692e8] <env>
#> └─loop = [1:0x558a72b692e8]
```

**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] "0x562e6757cb20" "0x562e6757cb20"
#> [1] "0x558a751c8be8" "0x558a751c8be8"
lobstr::obj_addrs(list(e2, e1$loop))
#> [1] "0x562e675ca280" "0x562e675ca280"
#> [1] "0x558a75216348" "0x558a75216348"
```

**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: 0x562e629525a8>
#> <bytecode: 0x558a7059e5a8>
#> <environment: namespace:base>

mean <- 5
Expand Down Expand Up @@ -506,7 +506,7 @@ rlang::caller_env
#> {
#> parent.frame(n + 1)
#> }
#> <bytecode: 0x562e634718d0>
#> <bytecode: 0x558a710bd8d0>
#> <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-24
#> date 2023-12-31
#> 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: 0x56044cf55118>
#> <environment: 0x56269fbe7e18>
#> Parent: <environment: global>
```

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

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

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

---
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-24
#> date 2023-12-31
#> 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: 0x562764fbe5a8>
#> <bytecode: 0x55d34a3275a8>
#> <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-24
#> date 2023-12-31
#> 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: 0x56538a2c9ab0>
#> <bytecode: 0x556cfd712ab0>
#> <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: 0x56538e535330>
#> <environment: 0x56538e534488>
#> <bytecode: 0x556d01983cb0>
#> <environment: 0x556d01982ba0>
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: 0x56538e6da210>
#> <environment: 0x556d01b28e68>

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

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

Expand All @@ -281,7 +281,7 @@ scales::number_format
#> scale_cut = scale_cut, trim = trim, ...)
#> }
#> }
#> <bytecode: 0x56538ec810f8>
#> <bytecode: 0x556d020cfbc8>
#> <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: 0x56538a64e5e0>
#> <environment: 0x556cfdac76a0>

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

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: 0x56538d79f860>
#> <environment: 0x556d00bef850>
```

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: 0x56538e3d90b0>
#> <environment: 0x556d0181e450>
#> 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 28Β΅s 29.6Β΅s 32798. 12.9KB 42.7
#> 2 LL2 14.4Β΅s 15.1Β΅s 63109. 0B 50.5
#> 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
```

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 39.9Β΅s 41.9Β΅s 22649.
#> 2 10 LL2 17.2Β΅s 18Β΅s 54745.
#> 3 20 LL1 43Β΅s 44.5Β΅s 22146.
#> 4 20 LL2 16.8Β΅s 17.7Β΅s 55763.
#> 5 50 LL1 46.8Β΅s 48.4Β΅s 20369.
#> 6 50 LL2 16.2Β΅s 17.1Β΅s 57476.
#> 7 100 LL1 62.1Β΅s 63.9Β΅s 15344.
#> 8 100 LL2 17.5Β΅s 18.3Β΅s 53784.
#> 9 1000 LL1 857.2Β΅s 963.9Β΅s 1083.
#> 10 1000 LL2 54.1Β΅s 55.4Β΅s 17678.
#> 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.

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-24
#> date 2023-12-31
#> pandoc 3.1.8 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
Expand Down
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: 0x55db5dac6ef0>
#> <bytecode: 0x55d90290c0b8>
#> <environment: namespace:purrr>
```

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

purrr:::capture_error
Expand All @@ -132,7 +132,7 @@ purrr:::capture_error
#> list(result = otherwise, error = e)
#> })
#> }
#> <bytecode: 0x55db5dcba198>
#> <bytecode: 0x55d902b04180>
#> <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-24 00:42:42.89723
#> Function called at: 2023-12-24 00:42:47.904205
#> Function called at: 2023-12-24 00:42:52.90958
#> Function called at: 2023-12-24 00:43:00.918007
#> 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
```

---
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-24
#> date 2023-12-31
#> pandoc 3.1.8 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────
Expand Down
Loading

0 comments on commit 2988696

Please sign in to comment.