You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: part-gen-prog/02-prog-functions.qmd
+32-2Lines changed: 32 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -384,8 +384,38 @@ not(False) or not(False)
384
384
**Functions** are sets of instructions that take **arguments** and **return** values.
385
385
Strictly speaking, mathematical operators (like those above) are a special type of functions -- but we aren't going to get into that now.
386
386
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
+
{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
+
387
417
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.
389
419
390
420
::: callout-warning
391
421
### Cheat Sheets!
@@ -399,7 +429,7 @@ It may be helpful at this point to print out the [R reference card](../files/Sho
399
429
400
430
[^02-prog-functions-2]: From http://sixthresearcher.com/wp-content/uploads/2016/12/Python3_reference_cheat_sheet.pdf
401
431
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.
403
433
In Python, methods are applied using the syntax `variable.method_name()`.
404
434
So, you can get the length of a string variable `my_string` using `my_string.length()`.
Copy file name to clipboardExpand all lines: part-tools/05-git-and-github.qmd
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -245,6 +245,8 @@ To create a repository, you can start with your local computer first, or you can
245
245
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.
246
246
:::
247
247
248
+
::: panel-tabset
249
+
248
250
#### Local repository first
249
251
250
252
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:
340
342
<iframewidth="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>
341
343
:::
342
344
345
+
:::
346
+
343
347
### Adding files
344
348
345
349
`git add` tells git that you want it to track a particular file.
0 commit comments