-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add R basics lesson #45
base: main
Are you sure you want to change the base?
Conversation
::: {.callout-important} | ||
Note this is **NOT** a standard mathematical notation. | ||
::: | ||
Writing long chains of code with the pipe makes your code easier to read and can be documented with comments. The equivalent code without the pipe is `mean(exp(rnorm(1000)))`, since `rnorm(1000)` is 'piped' into the `exp()` function giving `exp(rnorm(1000))` which is then piped into the `mean()` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add something in here about reading from inside to out? Maybe:
Writing long chains of code with the pipe makes your code easier to read and can be documented with comments. The equivalent code without the pipe is `mean(exp(rnorm(1000)))`, since `rnorm(1000)` is 'piped' into the `exp()` function giving `exp(rnorm(1000))` which is then piped into the `mean()` function. | |
Writing long chains of code with the pipe makes your code easier to read and can be documented with comments. The equivalent code without the pipe is | |
```{webr} | |
#| exercise: pipe-no-pipe | |
#| autorun: true | |
mean(exp(rnorm(1000))) |
which you read from the innermost set of brackets outwards. With the pipe, we say rnorm(1000)
is 'piped' into the exp()
function giving exp(rnorm(1000))
which is then piped into the mean()
function.
I've put it in a webr block just so the syntax highlighting looks a bit nicer but it's probably overkill.
c( | ||
"Did you extract the 6th element using its index in square brackets?" = !search_ast(.code, .expr = x[6]), | ||
"Did you access elements 2 to 4 using their indices in square brackets?" = !search_ast(.code, .expr = y[2:4]) | ||
```{webr} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives me an error:
Error in checking code for
reuse
: argument is missing, with no default
#| check: true | ||
library(qlcheckr) | ||
apply_checks( | ||
"Use the seq() function with an appropriate `from` and `to` inputs to slice the letters." = !search_ast(ql_ast(), .expr = seq(1, 10)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This says incorrect if you use seq(from = 1, to = 10)
even though I think that's what the error message wants!
|
||
You will get a different outcome ("Head" or "Tail") every time when you | ||
call the function `flip_a_coin`. | ||
```{webr} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a comment here to scroll down the output to see all the column names as they don't all fit on one row.
No description provided.