Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add R basics lesson #45

wants to merge 1 commit into from

Conversation

mitchelloharawild
Copy link
Collaborator

No description provided.

@mitchelloharawild mitchelloharawild added the content Add or Update Modules label Feb 21, 2025
::: {.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.

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:

Suggested change
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}

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))

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}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Add or Update Modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants