What does the magrittr dot/period (“.”) operator do when it's at the very beginning of a pipeline?












3















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.










share|improve this question

























  • It's the previous data.frame.

    – Rui Barradas
    Nov 22 '18 at 18:31











  • I'm not sure why that would be or where the documentation is?

    – nicolaskruchten
    Nov 22 '18 at 18:40











  • Documentation? Here we go: magrittr v1.5, vignette. Cheers

    – Henrik
    Nov 22 '18 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 '18 at 19:11











  • it seems like it means that it will act like function(x) {x} is that right?

    – nicolaskruchten
    Nov 22 '18 at 19:21


















3















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.










share|improve this question

























  • It's the previous data.frame.

    – Rui Barradas
    Nov 22 '18 at 18:31











  • I'm not sure why that would be or where the documentation is?

    – nicolaskruchten
    Nov 22 '18 at 18:40











  • Documentation? Here we go: magrittr v1.5, vignette. Cheers

    – Henrik
    Nov 22 '18 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 '18 at 19:11











  • it seems like it means that it will act like function(x) {x} is that right?

    – nicolaskruchten
    Nov 22 '18 at 19:21
















3












3








3








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 2:07







nicolaskruchten

















asked Nov 22 '18 at 18:30









nicolaskruchtennicolaskruchten

13.4k65071




13.4k65071













  • It's the previous data.frame.

    – Rui Barradas
    Nov 22 '18 at 18:31











  • I'm not sure why that would be or where the documentation is?

    – nicolaskruchten
    Nov 22 '18 at 18:40











  • Documentation? Here we go: magrittr v1.5, vignette. Cheers

    – Henrik
    Nov 22 '18 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 '18 at 19:11











  • it seems like it means that it will act like function(x) {x} is that right?

    – nicolaskruchten
    Nov 22 '18 at 19:21





















  • It's the previous data.frame.

    – Rui Barradas
    Nov 22 '18 at 18:31











  • I'm not sure why that would be or where the documentation is?

    – nicolaskruchten
    Nov 22 '18 at 18:40











  • Documentation? Here we go: magrittr v1.5, vignette. Cheers

    – Henrik
    Nov 22 '18 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 '18 at 19:11











  • it seems like it means that it will act like function(x) {x} is that right?

    – nicolaskruchten
    Nov 22 '18 at 19:21



















It's the previous data.frame.

– Rui Barradas
Nov 22 '18 at 18:31





It's the previous data.frame.

– Rui Barradas
Nov 22 '18 at 18:31













I'm not sure why that would be or where the documentation is?

– nicolaskruchten
Nov 22 '18 at 18:40





I'm not sure why that would be or where the documentation is?

– nicolaskruchten
Nov 22 '18 at 18:40













Documentation? Here we go: magrittr v1.5, vignette. Cheers

– Henrik
Nov 22 '18 at 18:41







Documentation? Here we go: magrittr v1.5, vignette. Cheers

– Henrik
Nov 22 '18 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 '18 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 '18 at 19:11













it seems like it means that it will act like function(x) {x} is that right?

– nicolaskruchten
Nov 22 '18 at 19:21







it seems like it means that it will act like function(x) {x} is that right?

– nicolaskruchten
Nov 22 '18 at 19:21














1 Answer
1






active

oldest

votes


















3














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.






share|improve this answer
























  • Thanks! So is it fair to say that the . by itself is equivalent to function(x){x} in this context?

    – nicolaskruchten
    Nov 23 '18 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 '18 at 21:07











  • ahhh that's very helpful, thank you :)

    – nicolaskruchten
    Nov 24 '18 at 2:08











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
});


}
});














draft saved

draft discarded


















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









3














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.






share|improve this answer
























  • Thanks! So is it fair to say that the . by itself is equivalent to function(x){x} in this context?

    – nicolaskruchten
    Nov 23 '18 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 '18 at 21:07











  • ahhh that's very helpful, thank you :)

    – nicolaskruchten
    Nov 24 '18 at 2:08
















3














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.






share|improve this answer
























  • Thanks! So is it fair to say that the . by itself is equivalent to function(x){x} in this context?

    – nicolaskruchten
    Nov 23 '18 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 '18 at 21:07











  • ahhh that's very helpful, thank you :)

    – nicolaskruchten
    Nov 24 '18 at 2:08














3












3








3







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 19:54









AxemanAxeman

18.9k54459




18.9k54459













  • Thanks! So is it fair to say that the . by itself is equivalent to function(x){x} in this context?

    – nicolaskruchten
    Nov 23 '18 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 '18 at 21:07











  • ahhh that's very helpful, thank you :)

    – nicolaskruchten
    Nov 24 '18 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 '18 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 '18 at 21:07











  • ahhh that's very helpful, thank you :)

    – nicolaskruchten
    Nov 24 '18 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 '18 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 '18 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 '18 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 '18 at 21:07













ahhh that's very helpful, thank you :)

– nicolaskruchten
Nov 24 '18 at 2:08





ahhh that's very helpful, thank you :)

– nicolaskruchten
Nov 24 '18 at 2:08




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?