tidyeval functions and problems with `View()`
Code chunk #1 and #2 are identical, except for line number 14. Code chunk #1 uses a print()
call and code chunk #2 uses the View()
call. Code chunk #1 works fine. Code chunk #2 gives the error "Error in FUN(X[[i]], ...) : object 'cal.date' not found"
. Why?
1
library(tidyverse)
set.seed(1)
graph.data <- tibble(cal.date = as.Date(40100:40129, origin = "1899-12-30"),
random_num = rnorm(30, 8, 5))
child_function <- function(df, variable, hor.line = 6) {
variable <- enquo(variable)
df <- df %>% mutate(mutation = 2 * !!variable, horizontal.line = hor.line)
}
parent_function <- function(df, date, variable, hor.line = 6) {
date <- enquo(date)
variable <- enquo(variable)
df <- df %>% child_function(!!variable, hor.line) %>% print() # LINE 14
p <- ggplot(df, aes(!!date, mutation)) +
geom_point() +
geom_hline(aes(yintercept = hor.line))
p
}
parent_function(graph.data, date = cal.date, variable = random_num, hor.line = 8)
2
library(tidyverse)
set.seed(1)
graph.data <- tibble(cal.date = as.Date(40100:40129, origin = "1899-12-30"),
random_num = rnorm(30, 8, 5))
child_function <- function(df, variable, hor.line = 6) {
variable <- enquo(variable)
df <- df %>% mutate(mutation = 2 * !!variable, horizontal.line = hor.line)
}
parent_function <- function(df, date, variable, hor.line = 6) {
date <- enquo(date)
variable <- enquo(variable)
df <- df %>% child_function(!!variable, hor.line) %>% View() # LINE 14
p <- ggplot(df, aes(!!date, mutation)) +
geom_point() +
geom_hline(aes(yintercept = hor.line))
p
}
parent_function(graph.data, date = cal.date, variable = random_num, hor.line = 8)
r function dplyr tidyeval
add a comment |
Code chunk #1 and #2 are identical, except for line number 14. Code chunk #1 uses a print()
call and code chunk #2 uses the View()
call. Code chunk #1 works fine. Code chunk #2 gives the error "Error in FUN(X[[i]], ...) : object 'cal.date' not found"
. Why?
1
library(tidyverse)
set.seed(1)
graph.data <- tibble(cal.date = as.Date(40100:40129, origin = "1899-12-30"),
random_num = rnorm(30, 8, 5))
child_function <- function(df, variable, hor.line = 6) {
variable <- enquo(variable)
df <- df %>% mutate(mutation = 2 * !!variable, horizontal.line = hor.line)
}
parent_function <- function(df, date, variable, hor.line = 6) {
date <- enquo(date)
variable <- enquo(variable)
df <- df %>% child_function(!!variable, hor.line) %>% print() # LINE 14
p <- ggplot(df, aes(!!date, mutation)) +
geom_point() +
geom_hline(aes(yintercept = hor.line))
p
}
parent_function(graph.data, date = cal.date, variable = random_num, hor.line = 8)
2
library(tidyverse)
set.seed(1)
graph.data <- tibble(cal.date = as.Date(40100:40129, origin = "1899-12-30"),
random_num = rnorm(30, 8, 5))
child_function <- function(df, variable, hor.line = 6) {
variable <- enquo(variable)
df <- df %>% mutate(mutation = 2 * !!variable, horizontal.line = hor.line)
}
parent_function <- function(df, date, variable, hor.line = 6) {
date <- enquo(date)
variable <- enquo(variable)
df <- df %>% child_function(!!variable, hor.line) %>% View() # LINE 14
p <- ggplot(df, aes(!!date, mutation)) +
geom_point() +
geom_hline(aes(yintercept = hor.line))
p
}
parent_function(graph.data, date = cal.date, variable = random_num, hor.line = 8)
r function dplyr tidyeval
add a comment |
Code chunk #1 and #2 are identical, except for line number 14. Code chunk #1 uses a print()
call and code chunk #2 uses the View()
call. Code chunk #1 works fine. Code chunk #2 gives the error "Error in FUN(X[[i]], ...) : object 'cal.date' not found"
. Why?
1
library(tidyverse)
set.seed(1)
graph.data <- tibble(cal.date = as.Date(40100:40129, origin = "1899-12-30"),
random_num = rnorm(30, 8, 5))
child_function <- function(df, variable, hor.line = 6) {
variable <- enquo(variable)
df <- df %>% mutate(mutation = 2 * !!variable, horizontal.line = hor.line)
}
parent_function <- function(df, date, variable, hor.line = 6) {
date <- enquo(date)
variable <- enquo(variable)
df <- df %>% child_function(!!variable, hor.line) %>% print() # LINE 14
p <- ggplot(df, aes(!!date, mutation)) +
geom_point() +
geom_hline(aes(yintercept = hor.line))
p
}
parent_function(graph.data, date = cal.date, variable = random_num, hor.line = 8)
2
library(tidyverse)
set.seed(1)
graph.data <- tibble(cal.date = as.Date(40100:40129, origin = "1899-12-30"),
random_num = rnorm(30, 8, 5))
child_function <- function(df, variable, hor.line = 6) {
variable <- enquo(variable)
df <- df %>% mutate(mutation = 2 * !!variable, horizontal.line = hor.line)
}
parent_function <- function(df, date, variable, hor.line = 6) {
date <- enquo(date)
variable <- enquo(variable)
df <- df %>% child_function(!!variable, hor.line) %>% View() # LINE 14
p <- ggplot(df, aes(!!date, mutation)) +
geom_point() +
geom_hline(aes(yintercept = hor.line))
p
}
parent_function(graph.data, date = cal.date, variable = random_num, hor.line = 8)
r function dplyr tidyeval
Code chunk #1 and #2 are identical, except for line number 14. Code chunk #1 uses a print()
call and code chunk #2 uses the View()
call. Code chunk #1 works fine. Code chunk #2 gives the error "Error in FUN(X[[i]], ...) : object 'cal.date' not found"
. Why?
1
library(tidyverse)
set.seed(1)
graph.data <- tibble(cal.date = as.Date(40100:40129, origin = "1899-12-30"),
random_num = rnorm(30, 8, 5))
child_function <- function(df, variable, hor.line = 6) {
variable <- enquo(variable)
df <- df %>% mutate(mutation = 2 * !!variable, horizontal.line = hor.line)
}
parent_function <- function(df, date, variable, hor.line = 6) {
date <- enquo(date)
variable <- enquo(variable)
df <- df %>% child_function(!!variable, hor.line) %>% print() # LINE 14
p <- ggplot(df, aes(!!date, mutation)) +
geom_point() +
geom_hline(aes(yintercept = hor.line))
p
}
parent_function(graph.data, date = cal.date, variable = random_num, hor.line = 8)
2
library(tidyverse)
set.seed(1)
graph.data <- tibble(cal.date = as.Date(40100:40129, origin = "1899-12-30"),
random_num = rnorm(30, 8, 5))
child_function <- function(df, variable, hor.line = 6) {
variable <- enquo(variable)
df <- df %>% mutate(mutation = 2 * !!variable, horizontal.line = hor.line)
}
parent_function <- function(df, date, variable, hor.line = 6) {
date <- enquo(date)
variable <- enquo(variable)
df <- df %>% child_function(!!variable, hor.line) %>% View() # LINE 14
p <- ggplot(df, aes(!!date, mutation)) +
geom_point() +
geom_hline(aes(yintercept = hor.line))
p
}
parent_function(graph.data, date = cal.date, variable = random_num, hor.line = 8)
r function dplyr tidyeval
r function dplyr tidyeval
edited Nov 12 '18 at 20:25
Calum You
7,0171729
7,0171729
asked Nov 12 '18 at 20:12
stackinatorstackinator
1,214419
1,214419
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
View()
is a side effect function and does not return anything.
Use %T>%
from the magrittr
package instead of %>%
for your second case.
View()
ends the pipe such that you will want to have a T pipe
instead. I think you can see it more clearly like this
df %>% child_function(!!variable, hor.line) %>% View() -> df
vs.
df %>% child_function(!!variable, hor.line) %T>% View() -> df
1
I think this requires an explicitlibrary(magrittr)
– Calum You
Nov 12 '18 at 20:24
@CalumYou, You are right! I always forget thattidyverse
does not load it
– Jrakru56
Nov 12 '18 at 20:25
2
Yeah, it's a little annoying but magrittr has name collisions with other tidyverse functions (extract, set_names). I hope they rename one or the other at some point since having the T and assignment pipes is nice
– Calum You
Nov 12 '18 at 20:27
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269415%2ftidyeval-functions-and-problems-with-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
View()
is a side effect function and does not return anything.
Use %T>%
from the magrittr
package instead of %>%
for your second case.
View()
ends the pipe such that you will want to have a T pipe
instead. I think you can see it more clearly like this
df %>% child_function(!!variable, hor.line) %>% View() -> df
vs.
df %>% child_function(!!variable, hor.line) %T>% View() -> df
1
I think this requires an explicitlibrary(magrittr)
– Calum You
Nov 12 '18 at 20:24
@CalumYou, You are right! I always forget thattidyverse
does not load it
– Jrakru56
Nov 12 '18 at 20:25
2
Yeah, it's a little annoying but magrittr has name collisions with other tidyverse functions (extract, set_names). I hope they rename one or the other at some point since having the T and assignment pipes is nice
– Calum You
Nov 12 '18 at 20:27
add a comment |
View()
is a side effect function and does not return anything.
Use %T>%
from the magrittr
package instead of %>%
for your second case.
View()
ends the pipe such that you will want to have a T pipe
instead. I think you can see it more clearly like this
df %>% child_function(!!variable, hor.line) %>% View() -> df
vs.
df %>% child_function(!!variable, hor.line) %T>% View() -> df
1
I think this requires an explicitlibrary(magrittr)
– Calum You
Nov 12 '18 at 20:24
@CalumYou, You are right! I always forget thattidyverse
does not load it
– Jrakru56
Nov 12 '18 at 20:25
2
Yeah, it's a little annoying but magrittr has name collisions with other tidyverse functions (extract, set_names). I hope they rename one or the other at some point since having the T and assignment pipes is nice
– Calum You
Nov 12 '18 at 20:27
add a comment |
View()
is a side effect function and does not return anything.
Use %T>%
from the magrittr
package instead of %>%
for your second case.
View()
ends the pipe such that you will want to have a T pipe
instead. I think you can see it more clearly like this
df %>% child_function(!!variable, hor.line) %>% View() -> df
vs.
df %>% child_function(!!variable, hor.line) %T>% View() -> df
View()
is a side effect function and does not return anything.
Use %T>%
from the magrittr
package instead of %>%
for your second case.
View()
ends the pipe such that you will want to have a T pipe
instead. I think you can see it more clearly like this
df %>% child_function(!!variable, hor.line) %>% View() -> df
vs.
df %>% child_function(!!variable, hor.line) %T>% View() -> df
edited Nov 12 '18 at 20:26
answered Nov 12 '18 at 20:20
Jrakru56Jrakru56
597111
597111
1
I think this requires an explicitlibrary(magrittr)
– Calum You
Nov 12 '18 at 20:24
@CalumYou, You are right! I always forget thattidyverse
does not load it
– Jrakru56
Nov 12 '18 at 20:25
2
Yeah, it's a little annoying but magrittr has name collisions with other tidyverse functions (extract, set_names). I hope they rename one or the other at some point since having the T and assignment pipes is nice
– Calum You
Nov 12 '18 at 20:27
add a comment |
1
I think this requires an explicitlibrary(magrittr)
– Calum You
Nov 12 '18 at 20:24
@CalumYou, You are right! I always forget thattidyverse
does not load it
– Jrakru56
Nov 12 '18 at 20:25
2
Yeah, it's a little annoying but magrittr has name collisions with other tidyverse functions (extract, set_names). I hope they rename one or the other at some point since having the T and assignment pipes is nice
– Calum You
Nov 12 '18 at 20:27
1
1
I think this requires an explicit
library(magrittr)
– Calum You
Nov 12 '18 at 20:24
I think this requires an explicit
library(magrittr)
– Calum You
Nov 12 '18 at 20:24
@CalumYou, You are right! I always forget that
tidyverse
does not load it– Jrakru56
Nov 12 '18 at 20:25
@CalumYou, You are right! I always forget that
tidyverse
does not load it– Jrakru56
Nov 12 '18 at 20:25
2
2
Yeah, it's a little annoying but magrittr has name collisions with other tidyverse functions (extract, set_names). I hope they rename one or the other at some point since having the T and assignment pipes is nice
– Calum You
Nov 12 '18 at 20:27
Yeah, it's a little annoying but magrittr has name collisions with other tidyverse functions (extract, set_names). I hope they rename one or the other at some point since having the T and assignment pipes is nice
– Calum You
Nov 12 '18 at 20:27
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269415%2ftidyeval-functions-and-problems-with-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown