Skip to content

Commit

Permalink
Finishing Question 2
Browse files Browse the repository at this point in the history
  • Loading branch information
hleeutah committed Jan 26, 2023
1 parent ad3b0ba commit b5b5f25
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
13 changes: 9 additions & 4 deletions 03-functions-and-datatable/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,20 @@ <h2>Question 1: <strong>Ellipsis</strong></h2>
<pre><code>## num [1:3] 1 2 3
## chr [1:2] &quot;blue&quot; &quot;red&quot;</code></pre>
<pre><code>## $x
## [1] &quot;0x7f98f4ebd5f8&quot;
## [1] &quot;0x7fa1a3519d58&quot;
##
## $y
## [1] &quot;0x7f99158d2608&quot;</code></pre>
## [1] &quot;0x7fa1a3521048&quot;</code></pre>
<p>Knit the document, commit your changes, and push them to GitHub.</p>
</div>
<div id="question-2-lady-evaluation" class="section level2">
<h2>Question 2: <strong>Lady evaluation</strong></h2>
<div id="question-2-lazy-evaluation" class="section level2">
<h2>Question 2: <strong>Lazy evaluation</strong></h2>
<p>A concept we did not review was lazy evaluation. Write a function with two arguments (<code>a</code> and <code>b</code>) that only uses one of them as an integer, and then call the function passing the following arguments <code>(1, this_stuff)</code></p>
<pre class="r"><code>#lazy evaluation =&gt; R won&#39;t evaluate unless it needs it.

func&lt;-function(a,b){print(a)}
func(1,this_value_doesnt_exists) #works b/c R does lazy evaluation.</code></pre>
<pre><code>## [1] 1</code></pre>
<p>Knit the document, commit your changes, and push them to GitHub.</p>
</div>
<div id="question-3-putting-all-together" class="section level2">
Expand Down
17 changes: 11 additions & 6 deletions 03-functions-and-datatable/README.qmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
title: "Lab 03 - Functions and data.table"
format:
html:
embed-resources: true
editor_options:
chunk_output_type: console
# format:
# html:
# embed-resources: true
# editor_options:
# chunk_output_type: console
format: gfm
---

# Learning goals
Expand Down Expand Up @@ -122,11 +123,15 @@ test_function(x=c(1,2,3), y=c("blue","red"))
Knit the document, commit your changes, and push them to GitHub.


## Question 2: **Lady evaluation**
## Question 2: **Lazy evaluation**

A concept we did not review was lazy evaluation. Write a function with two arguments (`a` and `b`) that only uses one of them as an integer, and then call the function passing the following arguments `(1, this_stuff)`

```{r}
#lazy evaluation => R won't evaluate unless it needs it.
func<-function(a,b){print(a)}
func(1,this_value_doesnt_exists) #works b/c R does lazy evaluation.
```

Expand Down

1 comment on commit b5b5f25

@gvegayon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

Please sign in to comment.