What does the magrittr dot/period (“.”) operator do when it's at the very beginning of a pipeline?
I don't understand what the .
in the following code is doing or where to find documentation for it:
library(tidyverse)
ggplot(iris) +
geom_point(
aes(x=Sepal.Length, y=Sepal.Width),
data = . %>% filter(Species == 'setosa')
)
This appears to be behaving quite differently from the usage described in What does the dplyr period character "." reference? where the .
does not appear in the left-hand-most position.
The docs here say merely
A pipeline with a dot (.) as LHS will create a unary function. This is
used to define the aggregator function.
but this is not at all clear to me and I'm hoping for more information.
r ggplot2 magrittr
|
show 1 more comment
I don't understand what the .
in the following code is doing or where to find documentation for it:
library(tidyverse)
ggplot(iris) +
geom_point(
aes(x=Sepal.Length, y=Sepal.Width),
data = . %>% filter(Species == 'setosa')
)
This appears to be behaving quite differently from the usage described in What does the dplyr period character "." reference? where the .
does not appear in the left-hand-most position.
The docs here say merely
A pipeline with a dot (.) as LHS will create a unary function. This is
used to define the aggregator function.
but this is not at all clear to me and I'm hoping for more information.
r ggplot2 magrittr
It's the previous data.frame.
– Rui Barradas
Nov 22 at 18:31
I'm not sure why that would be or where the documentation is?
– nicolaskruchten
Nov 22 at 18:40
Documentation? Here we go: magrittr v1.5, vignette. Cheers
– Henrik
Nov 22 at 18:41
The only explanation in those docs is "A pipeline with a dot (.) as LHS will create a unary function. This is used to define the aggregator function." ... i was hoping for MORE information by asking this question...
– nicolaskruchten
Nov 22 at 19:11
it seems like it means that it will act likefunction(x) {x}
is that right?
– nicolaskruchten
Nov 22 at 19:21
|
show 1 more comment
I don't understand what the .
in the following code is doing or where to find documentation for it:
library(tidyverse)
ggplot(iris) +
geom_point(
aes(x=Sepal.Length, y=Sepal.Width),
data = . %>% filter(Species == 'setosa')
)
This appears to be behaving quite differently from the usage described in What does the dplyr period character "." reference? where the .
does not appear in the left-hand-most position.
The docs here say merely
A pipeline with a dot (.) as LHS will create a unary function. This is
used to define the aggregator function.
but this is not at all clear to me and I'm hoping for more information.
r ggplot2 magrittr
I don't understand what the .
in the following code is doing or where to find documentation for it:
library(tidyverse)
ggplot(iris) +
geom_point(
aes(x=Sepal.Length, y=Sepal.Width),
data = . %>% filter(Species == 'setosa')
)
This appears to be behaving quite differently from the usage described in What does the dplyr period character "." reference? where the .
does not appear in the left-hand-most position.
The docs here say merely
A pipeline with a dot (.) as LHS will create a unary function. This is
used to define the aggregator function.
but this is not at all clear to me and I'm hoping for more information.
r ggplot2 magrittr
r ggplot2 magrittr
edited Nov 24 at 2:07
asked Nov 22 at 18:30
nicolaskruchten
13.1k64971
13.1k64971
It's the previous data.frame.
– Rui Barradas
Nov 22 at 18:31
I'm not sure why that would be or where the documentation is?
– nicolaskruchten
Nov 22 at 18:40
Documentation? Here we go: magrittr v1.5, vignette. Cheers
– Henrik
Nov 22 at 18:41
The only explanation in those docs is "A pipeline with a dot (.) as LHS will create a unary function. This is used to define the aggregator function." ... i was hoping for MORE information by asking this question...
– nicolaskruchten
Nov 22 at 19:11
it seems like it means that it will act likefunction(x) {x}
is that right?
– nicolaskruchten
Nov 22 at 19:21
|
show 1 more comment
It's the previous data.frame.
– Rui Barradas
Nov 22 at 18:31
I'm not sure why that would be or where the documentation is?
– nicolaskruchten
Nov 22 at 18:40
Documentation? Here we go: magrittr v1.5, vignette. Cheers
– Henrik
Nov 22 at 18:41
The only explanation in those docs is "A pipeline with a dot (.) as LHS will create a unary function. This is used to define the aggregator function." ... i was hoping for MORE information by asking this question...
– nicolaskruchten
Nov 22 at 19:11
it seems like it means that it will act likefunction(x) {x}
is that right?
– nicolaskruchten
Nov 22 at 19:21
It's the previous data.frame.
– Rui Barradas
Nov 22 at 18:31
It's the previous data.frame.
– Rui Barradas
Nov 22 at 18:31
I'm not sure why that would be or where the documentation is?
– nicolaskruchten
Nov 22 at 18:40
I'm not sure why that would be or where the documentation is?
– nicolaskruchten
Nov 22 at 18:40
Documentation? Here we go: magrittr v1.5, vignette. Cheers
– Henrik
Nov 22 at 18:41
Documentation? Here we go: magrittr v1.5, vignette. Cheers
– Henrik
Nov 22 at 18:41
The only explanation in those docs is "A pipeline with a dot (.) as LHS will create a unary function. This is used to define the aggregator function." ... i was hoping for MORE information by asking this question...
– nicolaskruchten
Nov 22 at 19:11
The only explanation in those docs is "A pipeline with a dot (.) as LHS will create a unary function. This is used to define the aggregator function." ... i was hoping for MORE information by asking this question...
– nicolaskruchten
Nov 22 at 19:11
it seems like it means that it will act like
function(x) {x}
is that right?– nicolaskruchten
Nov 22 at 19:21
it seems like it means that it will act like
function(x) {x}
is that right?– nicolaskruchten
Nov 22 at 19:21
|
show 1 more comment
1 Answer
1
active
oldest
votes
The confusion here can actually come from two places.
First, yes, the . %>% something()
syntax creates a "unary" function that takes one argument. So:
. %>% filter(Species == 'setosa')
is equivalent to
function(.) filter(., Species == 'setosa')
The second part here is that ggplot2
layers can actually take a function as their data
argument. From e.g. ?geom_point
:
The data to be displayed in this layer. There are three options:
...
A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data.
So the function that is passed to geom_point
will always be applied to the default plot data (i.e. the data defined in ggplot()
).
Note that your linked question concerns the use of .
in funs()
, which is not directly related to it's use here.
Thanks! So is it fair to say that the.
by itself is equivalent tofunction(x){x}
in this context?
– nicolaskruchten
Nov 23 at 20:41
.
by itself does nothing, it's the%>%
that recognizes it and does all the magic. So you really. %>% something
as a combination for a function to be created. You can look at the source of the pipe and see it explicitly checks if the left hand side (LHS) is a placeholder (i.e..
), so it is programmed as a special case.
– Axeman
Nov 23 at 21:07
ahhh that's very helpful, thank you :)
– nicolaskruchten
Nov 24 at 2:08
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%2f53436488%2fwhat-does-the-magrittr-dot-period-operator-do-when-its-at-the-very-beginn%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
The confusion here can actually come from two places.
First, yes, the . %>% something()
syntax creates a "unary" function that takes one argument. So:
. %>% filter(Species == 'setosa')
is equivalent to
function(.) filter(., Species == 'setosa')
The second part here is that ggplot2
layers can actually take a function as their data
argument. From e.g. ?geom_point
:
The data to be displayed in this layer. There are three options:
...
A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data.
So the function that is passed to geom_point
will always be applied to the default plot data (i.e. the data defined in ggplot()
).
Note that your linked question concerns the use of .
in funs()
, which is not directly related to it's use here.
Thanks! So is it fair to say that the.
by itself is equivalent tofunction(x){x}
in this context?
– nicolaskruchten
Nov 23 at 20:41
.
by itself does nothing, it's the%>%
that recognizes it and does all the magic. So you really. %>% something
as a combination for a function to be created. You can look at the source of the pipe and see it explicitly checks if the left hand side (LHS) is a placeholder (i.e..
), so it is programmed as a special case.
– Axeman
Nov 23 at 21:07
ahhh that's very helpful, thank you :)
– nicolaskruchten
Nov 24 at 2:08
add a comment |
The confusion here can actually come from two places.
First, yes, the . %>% something()
syntax creates a "unary" function that takes one argument. So:
. %>% filter(Species == 'setosa')
is equivalent to
function(.) filter(., Species == 'setosa')
The second part here is that ggplot2
layers can actually take a function as their data
argument. From e.g. ?geom_point
:
The data to be displayed in this layer. There are three options:
...
A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data.
So the function that is passed to geom_point
will always be applied to the default plot data (i.e. the data defined in ggplot()
).
Note that your linked question concerns the use of .
in funs()
, which is not directly related to it's use here.
Thanks! So is it fair to say that the.
by itself is equivalent tofunction(x){x}
in this context?
– nicolaskruchten
Nov 23 at 20:41
.
by itself does nothing, it's the%>%
that recognizes it and does all the magic. So you really. %>% something
as a combination for a function to be created. You can look at the source of the pipe and see it explicitly checks if the left hand side (LHS) is a placeholder (i.e..
), so it is programmed as a special case.
– Axeman
Nov 23 at 21:07
ahhh that's very helpful, thank you :)
– nicolaskruchten
Nov 24 at 2:08
add a comment |
The confusion here can actually come from two places.
First, yes, the . %>% something()
syntax creates a "unary" function that takes one argument. So:
. %>% filter(Species == 'setosa')
is equivalent to
function(.) filter(., Species == 'setosa')
The second part here is that ggplot2
layers can actually take a function as their data
argument. From e.g. ?geom_point
:
The data to be displayed in this layer. There are three options:
...
A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data.
So the function that is passed to geom_point
will always be applied to the default plot data (i.e. the data defined in ggplot()
).
Note that your linked question concerns the use of .
in funs()
, which is not directly related to it's use here.
The confusion here can actually come from two places.
First, yes, the . %>% something()
syntax creates a "unary" function that takes one argument. So:
. %>% filter(Species == 'setosa')
is equivalent to
function(.) filter(., Species == 'setosa')
The second part here is that ggplot2
layers can actually take a function as their data
argument. From e.g. ?geom_point
:
The data to be displayed in this layer. There are three options:
...
A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data.
So the function that is passed to geom_point
will always be applied to the default plot data (i.e. the data defined in ggplot()
).
Note that your linked question concerns the use of .
in funs()
, which is not directly related to it's use here.
answered Nov 22 at 19:54
Axeman
18.3k44256
18.3k44256
Thanks! So is it fair to say that the.
by itself is equivalent tofunction(x){x}
in this context?
– nicolaskruchten
Nov 23 at 20:41
.
by itself does nothing, it's the%>%
that recognizes it and does all the magic. So you really. %>% something
as a combination for a function to be created. You can look at the source of the pipe and see it explicitly checks if the left hand side (LHS) is a placeholder (i.e..
), so it is programmed as a special case.
– Axeman
Nov 23 at 21:07
ahhh that's very helpful, thank you :)
– nicolaskruchten
Nov 24 at 2:08
add a comment |
Thanks! So is it fair to say that the.
by itself is equivalent tofunction(x){x}
in this context?
– nicolaskruchten
Nov 23 at 20:41
.
by itself does nothing, it's the%>%
that recognizes it and does all the magic. So you really. %>% something
as a combination for a function to be created. You can look at the source of the pipe and see it explicitly checks if the left hand side (LHS) is a placeholder (i.e..
), so it is programmed as a special case.
– Axeman
Nov 23 at 21:07
ahhh that's very helpful, thank you :)
– nicolaskruchten
Nov 24 at 2:08
Thanks! So is it fair to say that the
.
by itself is equivalent to function(x){x}
in this context?– nicolaskruchten
Nov 23 at 20:41
Thanks! So is it fair to say that the
.
by itself is equivalent to function(x){x}
in this context?– nicolaskruchten
Nov 23 at 20:41
.
by itself does nothing, it's the %>%
that recognizes it and does all the magic. So you really . %>% something
as a combination for a function to be created. You can look at the source of the pipe and see it explicitly checks if the left hand side (LHS) is a placeholder (i.e. .
), so it is programmed as a special case.– Axeman
Nov 23 at 21:07
.
by itself does nothing, it's the %>%
that recognizes it and does all the magic. So you really . %>% something
as a combination for a function to be created. You can look at the source of the pipe and see it explicitly checks if the left hand side (LHS) is a placeholder (i.e. .
), so it is programmed as a special case.– Axeman
Nov 23 at 21:07
ahhh that's very helpful, thank you :)
– nicolaskruchten
Nov 24 at 2:08
ahhh that's very helpful, thank you :)
– nicolaskruchten
Nov 24 at 2:08
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%2f53436488%2fwhat-does-the-magrittr-dot-period-operator-do-when-its-at-the-very-beginn%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
It's the previous data.frame.
– Rui Barradas
Nov 22 at 18:31
I'm not sure why that would be or where the documentation is?
– nicolaskruchten
Nov 22 at 18:40
Documentation? Here we go: magrittr v1.5, vignette. Cheers
– Henrik
Nov 22 at 18:41
The only explanation in those docs is "A pipeline with a dot (.) as LHS will create a unary function. This is used to define the aggregator function." ... i was hoping for MORE information by asking this question...
– nicolaskruchten
Nov 22 at 19:11
it seems like it means that it will act like
function(x) {x}
is that right?– nicolaskruchten
Nov 22 at 19:21