Skip to content

Commit 62dc1d0

Browse files
author
Susan Vanderplas
committed
Book updates
1 parent 0044821 commit 62dc1d0

File tree

7 files changed

+41
-9
lines changed

7 files changed

+41
-9
lines changed

_freeze/part-gen-prog/02-prog-functions/execute-results/html.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.
-742 Bytes
Loading
952 Bytes
Loading

_freeze/part-tools/05-git-and-github/execute-results/html.json

Lines changed: 3 additions & 5 deletions
Large diffs are not rendered by default.

images/gen-prog/function-vocab.png

16.5 KB
Loading

part-gen-prog/02-prog-functions.qmd

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,38 @@ not(False) or not(False)
384384
**Functions** are sets of instructions that take **arguments** and **return** values.
385385
Strictly speaking, mathematical operators (like those above) are a special type of functions -- but we aren't going to get into that now.
386386

387+
::: callout-info
388+
### Function Vocabulary
389+
390+
Suppose I have a function called `add(x, y)` which takes two numbers and adds them together.
391+
392+
In this example, `add` is the function name, and `x` and `y` are **parameters**: placeholder names for information to be passed into the function.
393+
Not all functions have named parameters, but it is common for named parameters to provide some indication of what information is supposed to go in that spot.
394+
395+
When I call the function -- that is, I use it to add two numbers together, I have to pass in **arguments**.
396+
Arguments are values which are assigned to parameters in the function and affect the result.
397+
This is pretty technical and a bit nit-picky, but it's good to see information multiple times - we'll revisit functions in @sec-functions.
398+
399+
The **function call** would be `add(x = 3, y = 2)`, where 3 and 2 are the arguments.
400+
The function call would be evaluated and would **return** 5 as the answer (assuming that `add` does what it says it does).
401+
402+
403+
Let's see these words in a more concrete setting.
404+
405+
![Small excerpt from the R reference card, showing the `which.max` and `which.min` functions](../images/gen-prog/function-vocab.png){fig-alt="An image which has the heading 'Data selection and manipulation', and below that has the text 'which.max(x) returns the index of the greatest element of x' and 'which.min(x) returns the index of the smallest element of x'."}
406+
407+
- `which.max` and `which.min` are the function names
408+
- `x` is the parameter
409+
410+
When I type `which.max(x = c(2:10))` into the R console and hit Enter,
411+
- `c(2:10) = c(2, 3, 4, 5, 6, 7, 8, 9, 10)` is the argument
412+
- inside `which.max`, this argument has the name `x` (mostly helpful for debugging)
413+
- `which.max` will return 9, which is the index of `x` with the largest value (10)
414+
415+
:::
416+
387417
We're also not going to talk about how to create our own functions just yet.
388-
Instead, I'm going to show you how to *use* functions.
418+
Instead, in this chapter, let's figure out how to *use* functions.
389419

390420
::: callout-warning
391421
### Cheat Sheets!
@@ -399,7 +429,7 @@ It may be helpful at this point to print out the [R reference card](../files/Sho
399429

400430
[^02-prog-functions-2]: From http://sixthresearcher.com/wp-content/uploads/2016/12/Python3_reference_cheat_sheet.pdf
401431

402-
**Methods** are a special type of function that operate on a specific variable type.
432+
**Methods** are a special type of function that operate on a specific data type.
403433
In Python, methods are applied using the syntax `variable.method_name()`.
404434
So, you can get the length of a string variable `my_string` using `my_string.length()`.
405435

part-tools/05-git-and-github.qmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ To create a repository, you can start with your local computer first, or you can
245245
Both methods are relatively simple, but the options you choose depend on which method you're using, so be careful not to get them confused.
246246
:::
247247

248+
::: panel-tabset
249+
248250
#### Local repository first
249251

250252
Let's suppose you already have a folder on your machine named `hello-world-1` (you may want to create this folder now). You've created a starter document, say, a text file named README with "hello world" written in it.
@@ -340,6 +342,8 @@ Command line method:
340342
<iframe width="1048" height="590" src="https://www.youtube.com/embed/y4cpJ_VaRMg" title="Create the github repository first, using the command line to work with git" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
341343
:::
342344

345+
:::
346+
343347
### Adding files
344348

345349
`git add` tells git that you want it to track a particular file.

0 commit comments

Comments
 (0)