Skip to content

Commit

Permalink
changes/correctinso from our discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
aammd committed Nov 4, 2014
1 parent fd1c75d commit 03f17f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion 09_NSE/Alathea_Non-StandardEvaluation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ subset5 <- function(x, condition) {
na.omit(x[r, , drop = FALSE])
}
subset4(sample_df3, x > 8)
subset5(sample_df3, x > 8)
```

Apparently, nothing different happens
Expand Down
21 changes: 7 additions & 14 deletions 09_NSE/Andrew_NSE.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ pairwise.t.test(test$dat, test$fac)

```{r}
test2 <- data.frame(factorthatwehopehassomeexplanatorypowerbutthenagainitmightnot = gl(2, k = 5), dat = rnorm(10))
pairwise.t.test(test2$dat, test2$fac)
pairwise.t.test(test2$factorthatwehopehassomeexplanatorypowerbutthenagainitmightnot, test2$fac)
```
WHAT?!

I thought that these would return f(whatever_was_in_there) but it didn't, it returned X every time. But Why? Because
```{r}
Expand All @@ -58,10 +57,7 @@ deparse(substitute(x))
is the only thing that gets evalutated? x is never evaluated?

```{r error = TRUE}
f <- function(x){
force(x)
substitute(x)
}
f <- function(a) substitute(a)
g <- function(x) deparse(f(x))
g(1:10)
Expand Down Expand Up @@ -104,11 +100,8 @@ subset2 <- function(x, condition) {
res <- x
condition_call <- substitute(condition)
r <- eval(condition_call, x)
res <- x[r, ]
res <- as.data.frame(res)
names(res) <- names(x)
res
}
x[r, , drop = FALSE]
}
sample_df2 <- data.frame(x = 1:10)
subset2(sample_df2, x > 8)
Expand Down Expand Up @@ -152,7 +145,7 @@ evalq(2 + 2)
truth <- list(fact = "science is cool", fact2 = "but its hard to find work")
evalq(truth)
evalq(fact)
# evalq(fact)
evalq(fact, truth)
```

Expand Down Expand Up @@ -203,9 +196,9 @@ with(df, a + foo)
On the other hand, I never got into the habit of using `within`. I understand that it works like transform:

```{r}
tl <- list(a = rnorm(20), b = rpois(20, 10))
tl <- data.frame(a = rnorm(20), b = rpois(20, 10))
tl <- within(tl, sum(a, b))
tl <- within(tl, new <- sum(a, b))
tl
```

Expand Down

0 comments on commit 03f17f5

Please sign in to comment.