Why is := allowed as an infix operator?
I have come across the popular data.table
package and one thing in particular intrigued me. It has an in-place assignment operator
:=
This is not defined in base R. In fact if you didn't load the data.table
package, it would have raised an error if you had tried to used it (e.g., a := 2
) with the message:
Error: could not find function
":="
Also, why does :=
work? Why does R let you define :=
as infix operator while every other infix function has to be surrounded by %%
, e.g.
`:=` <- function(a, b)
paste(a,b)
"abc" := "def"
Clearly it's not meant to be an alternative syntax to %function.name%
for defining infix functions. Is data.table
exploiting some parsing quirks of R? Is it a hack? Will it be "patched" in the future?
r data.table colon-equals
add a comment |
I have come across the popular data.table
package and one thing in particular intrigued me. It has an in-place assignment operator
:=
This is not defined in base R. In fact if you didn't load the data.table
package, it would have raised an error if you had tried to used it (e.g., a := 2
) with the message:
Error: could not find function
":="
Also, why does :=
work? Why does R let you define :=
as infix operator while every other infix function has to be surrounded by %%
, e.g.
`:=` <- function(a, b)
paste(a,b)
"abc" := "def"
Clearly it's not meant to be an alternative syntax to %function.name%
for defining infix functions. Is data.table
exploiting some parsing quirks of R? Is it a hack? Will it be "patched" in the future?
r data.table colon-equals
5
Please take a look at the data.table documentation, starting maybe with the FAQ.
– Dirk Eddelbuettel
Oct 9 '14 at 2:39
1
@DirkEddelbuettel. I understand how it's used in data.table. But the fact that R allows for such an operator to be defined and not cause a syntax error is what intrigued me. It's a fundamental question about R and maybe how it parses code.
– xiaodai
Oct 9 '14 at 2:44
2
AFAIK it is local to data.table and only works with the[
subsetting. So your question is off-base (not an R quirk) which is why I sent you to the data.table docs which discuss this.
– Dirk Eddelbuettel
Oct 9 '14 at 2:49
1
@DirkEddelbuettel I think you are missing my point. I can define a funciton using:=
<- function(a,b) paste(a,b); and I can use it by doing "abc" := "def"! But all other infix function are in the form of %in.fn%?. Why?
– xiaodai
Oct 9 '14 at 2:57
2
This Q&A from Matt might be very relevant here as well.
– Arun
Oct 9 '14 at 6:51
add a comment |
I have come across the popular data.table
package and one thing in particular intrigued me. It has an in-place assignment operator
:=
This is not defined in base R. In fact if you didn't load the data.table
package, it would have raised an error if you had tried to used it (e.g., a := 2
) with the message:
Error: could not find function
":="
Also, why does :=
work? Why does R let you define :=
as infix operator while every other infix function has to be surrounded by %%
, e.g.
`:=` <- function(a, b)
paste(a,b)
"abc" := "def"
Clearly it's not meant to be an alternative syntax to %function.name%
for defining infix functions. Is data.table
exploiting some parsing quirks of R? Is it a hack? Will it be "patched" in the future?
r data.table colon-equals
I have come across the popular data.table
package and one thing in particular intrigued me. It has an in-place assignment operator
:=
This is not defined in base R. In fact if you didn't load the data.table
package, it would have raised an error if you had tried to used it (e.g., a := 2
) with the message:
Error: could not find function
":="
Also, why does :=
work? Why does R let you define :=
as infix operator while every other infix function has to be surrounded by %%
, e.g.
`:=` <- function(a, b)
paste(a,b)
"abc" := "def"
Clearly it's not meant to be an alternative syntax to %function.name%
for defining infix functions. Is data.table
exploiting some parsing quirks of R? Is it a hack? Will it be "patched" in the future?
r data.table colon-equals
r data.table colon-equals
edited Nov 13 '18 at 12:56
Moody_Mudskipper
22.7k32964
22.7k32964
asked Oct 9 '14 at 2:37
xiaodaixiaodai
4,110114871
4,110114871
5
Please take a look at the data.table documentation, starting maybe with the FAQ.
– Dirk Eddelbuettel
Oct 9 '14 at 2:39
1
@DirkEddelbuettel. I understand how it's used in data.table. But the fact that R allows for such an operator to be defined and not cause a syntax error is what intrigued me. It's a fundamental question about R and maybe how it parses code.
– xiaodai
Oct 9 '14 at 2:44
2
AFAIK it is local to data.table and only works with the[
subsetting. So your question is off-base (not an R quirk) which is why I sent you to the data.table docs which discuss this.
– Dirk Eddelbuettel
Oct 9 '14 at 2:49
1
@DirkEddelbuettel I think you are missing my point. I can define a funciton using:=
<- function(a,b) paste(a,b); and I can use it by doing "abc" := "def"! But all other infix function are in the form of %in.fn%?. Why?
– xiaodai
Oct 9 '14 at 2:57
2
This Q&A from Matt might be very relevant here as well.
– Arun
Oct 9 '14 at 6:51
add a comment |
5
Please take a look at the data.table documentation, starting maybe with the FAQ.
– Dirk Eddelbuettel
Oct 9 '14 at 2:39
1
@DirkEddelbuettel. I understand how it's used in data.table. But the fact that R allows for such an operator to be defined and not cause a syntax error is what intrigued me. It's a fundamental question about R and maybe how it parses code.
– xiaodai
Oct 9 '14 at 2:44
2
AFAIK it is local to data.table and only works with the[
subsetting. So your question is off-base (not an R quirk) which is why I sent you to the data.table docs which discuss this.
– Dirk Eddelbuettel
Oct 9 '14 at 2:49
1
@DirkEddelbuettel I think you are missing my point. I can define a funciton using:=
<- function(a,b) paste(a,b); and I can use it by doing "abc" := "def"! But all other infix function are in the form of %in.fn%?. Why?
– xiaodai
Oct 9 '14 at 2:57
2
This Q&A from Matt might be very relevant here as well.
– Arun
Oct 9 '14 at 6:51
5
5
Please take a look at the data.table documentation, starting maybe with the FAQ.
– Dirk Eddelbuettel
Oct 9 '14 at 2:39
Please take a look at the data.table documentation, starting maybe with the FAQ.
– Dirk Eddelbuettel
Oct 9 '14 at 2:39
1
1
@DirkEddelbuettel. I understand how it's used in data.table. But the fact that R allows for such an operator to be defined and not cause a syntax error is what intrigued me. It's a fundamental question about R and maybe how it parses code.
– xiaodai
Oct 9 '14 at 2:44
@DirkEddelbuettel. I understand how it's used in data.table. But the fact that R allows for such an operator to be defined and not cause a syntax error is what intrigued me. It's a fundamental question about R and maybe how it parses code.
– xiaodai
Oct 9 '14 at 2:44
2
2
AFAIK it is local to data.table and only works with the
[
subsetting. So your question is off-base (not an R quirk) which is why I sent you to the data.table docs which discuss this.– Dirk Eddelbuettel
Oct 9 '14 at 2:49
AFAIK it is local to data.table and only works with the
[
subsetting. So your question is off-base (not an R quirk) which is why I sent you to the data.table docs which discuss this.– Dirk Eddelbuettel
Oct 9 '14 at 2:49
1
1
@DirkEddelbuettel I think you are missing my point. I can define a funciton using
:=
<- function(a,b) paste(a,b); and I can use it by doing "abc" := "def"! But all other infix function are in the form of %in.fn%?. Why?– xiaodai
Oct 9 '14 at 2:57
@DirkEddelbuettel I think you are missing my point. I can define a funciton using
:=
<- function(a,b) paste(a,b); and I can use it by doing "abc" := "def"! But all other infix function are in the form of %in.fn%?. Why?– xiaodai
Oct 9 '14 at 2:57
2
2
This Q&A from Matt might be very relevant here as well.
– Arun
Oct 9 '14 at 6:51
This Q&A from Matt might be very relevant here as well.
– Arun
Oct 9 '14 at 6:51
add a comment |
2 Answers
2
active
oldest
votes
It is something that the base R parser recognizes and seems to parse as a left assign (at least in terms or order of operations and such). See the C source code for more details.
as.list(parse(text="a:=3")[[1]])
# [[1]]
# `:=`
#
# [[2]]
# a
#
# [[3]]
# [1] 3
As far as I can tell it's undocumented (as far as base R is concerned). But it is a function/operator you can change the behavior of
`:=`<-function(a,b) a+b
3 := 7
# [1] 10
As you can see there really isn't anything special about the ":" part itself. It just happens to be the start of a compound token.
12
@BondedDust Butdata.table
doesn't own that function. They really are relying on something lying around in the parser over which they have no control. Another package could redefinec
if they like. That's essentially what they are doing (there just happens to be no default implementation for:=
)
– MrFlick
Oct 9 '14 at 3:00
1
The OP did mention the data.table package so I would argue that in that setting:=
is "owned" by data.table. I suppose I would agree with you if you argued that the period-function (.()
) has separate (localalized) "ownership" bybquote
and plyr functions. And to my point, redefiningc()
is also a really bad idea.
– 42-
Oct 9 '14 at 3:02
15
@BondedDust But let's say thatdata.table
wanted to define~=
as new infix operator. They cannot do that because the parser would not recognize it (ieparse(text="a~=3")
would generate an error). The "specialness" of:=
is completely independent of the thedata.table
package. It is a big exception to the rule that custom infix operators require%
which seems to be the spirit of the OP's question as I read it.
– MrFlick
Oct 9 '14 at 3:07
3
+1 Nice job digging into the source!
– Joshua Ulrich
Oct 9 '14 at 15:19
1
I'm guessing at some point R Core was thinking of implementing:=
as an alternative to<-
since some languages use that as the assignment operator, but then dropped the idea after the parser was written.
– BrodieG
Apr 19 '17 at 22:03
|
show 4 more comments
It's not just a colon operator but rather :=
is a single operator formed by the colon and equal sign (just as the combination of "<" and "-" forms the assignment operator in base R). The :=
operator is an infix function that is defined to be part of the evaluation of the "j" argument inside the [.data.table
function. It creates or assigns a value to a column designated by its LHS argument using the result of evaluating its RHS.
4
To the downvoters who are not explaining their concerns. This answer was written to respond to the question as originally written. You can see its original title and content by clicking on the "edited ...." link.
– 42-
Oct 9 '14 at 17:39
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%2f26269423%2fwhy-is-allowed-as-an-infix-operator%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is something that the base R parser recognizes and seems to parse as a left assign (at least in terms or order of operations and such). See the C source code for more details.
as.list(parse(text="a:=3")[[1]])
# [[1]]
# `:=`
#
# [[2]]
# a
#
# [[3]]
# [1] 3
As far as I can tell it's undocumented (as far as base R is concerned). But it is a function/operator you can change the behavior of
`:=`<-function(a,b) a+b
3 := 7
# [1] 10
As you can see there really isn't anything special about the ":" part itself. It just happens to be the start of a compound token.
12
@BondedDust Butdata.table
doesn't own that function. They really are relying on something lying around in the parser over which they have no control. Another package could redefinec
if they like. That's essentially what they are doing (there just happens to be no default implementation for:=
)
– MrFlick
Oct 9 '14 at 3:00
1
The OP did mention the data.table package so I would argue that in that setting:=
is "owned" by data.table. I suppose I would agree with you if you argued that the period-function (.()
) has separate (localalized) "ownership" bybquote
and plyr functions. And to my point, redefiningc()
is also a really bad idea.
– 42-
Oct 9 '14 at 3:02
15
@BondedDust But let's say thatdata.table
wanted to define~=
as new infix operator. They cannot do that because the parser would not recognize it (ieparse(text="a~=3")
would generate an error). The "specialness" of:=
is completely independent of the thedata.table
package. It is a big exception to the rule that custom infix operators require%
which seems to be the spirit of the OP's question as I read it.
– MrFlick
Oct 9 '14 at 3:07
3
+1 Nice job digging into the source!
– Joshua Ulrich
Oct 9 '14 at 15:19
1
I'm guessing at some point R Core was thinking of implementing:=
as an alternative to<-
since some languages use that as the assignment operator, but then dropped the idea after the parser was written.
– BrodieG
Apr 19 '17 at 22:03
|
show 4 more comments
It is something that the base R parser recognizes and seems to parse as a left assign (at least in terms or order of operations and such). See the C source code for more details.
as.list(parse(text="a:=3")[[1]])
# [[1]]
# `:=`
#
# [[2]]
# a
#
# [[3]]
# [1] 3
As far as I can tell it's undocumented (as far as base R is concerned). But it is a function/operator you can change the behavior of
`:=`<-function(a,b) a+b
3 := 7
# [1] 10
As you can see there really isn't anything special about the ":" part itself. It just happens to be the start of a compound token.
12
@BondedDust Butdata.table
doesn't own that function. They really are relying on something lying around in the parser over which they have no control. Another package could redefinec
if they like. That's essentially what they are doing (there just happens to be no default implementation for:=
)
– MrFlick
Oct 9 '14 at 3:00
1
The OP did mention the data.table package so I would argue that in that setting:=
is "owned" by data.table. I suppose I would agree with you if you argued that the period-function (.()
) has separate (localalized) "ownership" bybquote
and plyr functions. And to my point, redefiningc()
is also a really bad idea.
– 42-
Oct 9 '14 at 3:02
15
@BondedDust But let's say thatdata.table
wanted to define~=
as new infix operator. They cannot do that because the parser would not recognize it (ieparse(text="a~=3")
would generate an error). The "specialness" of:=
is completely independent of the thedata.table
package. It is a big exception to the rule that custom infix operators require%
which seems to be the spirit of the OP's question as I read it.
– MrFlick
Oct 9 '14 at 3:07
3
+1 Nice job digging into the source!
– Joshua Ulrich
Oct 9 '14 at 15:19
1
I'm guessing at some point R Core was thinking of implementing:=
as an alternative to<-
since some languages use that as the assignment operator, but then dropped the idea after the parser was written.
– BrodieG
Apr 19 '17 at 22:03
|
show 4 more comments
It is something that the base R parser recognizes and seems to parse as a left assign (at least in terms or order of operations and such). See the C source code for more details.
as.list(parse(text="a:=3")[[1]])
# [[1]]
# `:=`
#
# [[2]]
# a
#
# [[3]]
# [1] 3
As far as I can tell it's undocumented (as far as base R is concerned). But it is a function/operator you can change the behavior of
`:=`<-function(a,b) a+b
3 := 7
# [1] 10
As you can see there really isn't anything special about the ":" part itself. It just happens to be the start of a compound token.
It is something that the base R parser recognizes and seems to parse as a left assign (at least in terms or order of operations and such). See the C source code for more details.
as.list(parse(text="a:=3")[[1]])
# [[1]]
# `:=`
#
# [[2]]
# a
#
# [[3]]
# [1] 3
As far as I can tell it's undocumented (as far as base R is concerned). But it is a function/operator you can change the behavior of
`:=`<-function(a,b) a+b
3 := 7
# [1] 10
As you can see there really isn't anything special about the ":" part itself. It just happens to be the start of a compound token.
answered Oct 9 '14 at 2:54
MrFlickMrFlick
122k11140168
122k11140168
12
@BondedDust Butdata.table
doesn't own that function. They really are relying on something lying around in the parser over which they have no control. Another package could redefinec
if they like. That's essentially what they are doing (there just happens to be no default implementation for:=
)
– MrFlick
Oct 9 '14 at 3:00
1
The OP did mention the data.table package so I would argue that in that setting:=
is "owned" by data.table. I suppose I would agree with you if you argued that the period-function (.()
) has separate (localalized) "ownership" bybquote
and plyr functions. And to my point, redefiningc()
is also a really bad idea.
– 42-
Oct 9 '14 at 3:02
15
@BondedDust But let's say thatdata.table
wanted to define~=
as new infix operator. They cannot do that because the parser would not recognize it (ieparse(text="a~=3")
would generate an error). The "specialness" of:=
is completely independent of the thedata.table
package. It is a big exception to the rule that custom infix operators require%
which seems to be the spirit of the OP's question as I read it.
– MrFlick
Oct 9 '14 at 3:07
3
+1 Nice job digging into the source!
– Joshua Ulrich
Oct 9 '14 at 15:19
1
I'm guessing at some point R Core was thinking of implementing:=
as an alternative to<-
since some languages use that as the assignment operator, but then dropped the idea after the parser was written.
– BrodieG
Apr 19 '17 at 22:03
|
show 4 more comments
12
@BondedDust Butdata.table
doesn't own that function. They really are relying on something lying around in the parser over which they have no control. Another package could redefinec
if they like. That's essentially what they are doing (there just happens to be no default implementation for:=
)
– MrFlick
Oct 9 '14 at 3:00
1
The OP did mention the data.table package so I would argue that in that setting:=
is "owned" by data.table. I suppose I would agree with you if you argued that the period-function (.()
) has separate (localalized) "ownership" bybquote
and plyr functions. And to my point, redefiningc()
is also a really bad idea.
– 42-
Oct 9 '14 at 3:02
15
@BondedDust But let's say thatdata.table
wanted to define~=
as new infix operator. They cannot do that because the parser would not recognize it (ieparse(text="a~=3")
would generate an error). The "specialness" of:=
is completely independent of the thedata.table
package. It is a big exception to the rule that custom infix operators require%
which seems to be the spirit of the OP's question as I read it.
– MrFlick
Oct 9 '14 at 3:07
3
+1 Nice job digging into the source!
– Joshua Ulrich
Oct 9 '14 at 15:19
1
I'm guessing at some point R Core was thinking of implementing:=
as an alternative to<-
since some languages use that as the assignment operator, but then dropped the idea after the parser was written.
– BrodieG
Apr 19 '17 at 22:03
12
12
@BondedDust But
data.table
doesn't own that function. They really are relying on something lying around in the parser over which they have no control. Another package could redefine c
if they like. That's essentially what they are doing (there just happens to be no default implementation for :=
)– MrFlick
Oct 9 '14 at 3:00
@BondedDust But
data.table
doesn't own that function. They really are relying on something lying around in the parser over which they have no control. Another package could redefine c
if they like. That's essentially what they are doing (there just happens to be no default implementation for :=
)– MrFlick
Oct 9 '14 at 3:00
1
1
The OP did mention the data.table package so I would argue that in that setting
:=
is "owned" by data.table. I suppose I would agree with you if you argued that the period-function ( .()
) has separate (localalized) "ownership" by bquote
and plyr functions. And to my point, redefining c()
is also a really bad idea.– 42-
Oct 9 '14 at 3:02
The OP did mention the data.table package so I would argue that in that setting
:=
is "owned" by data.table. I suppose I would agree with you if you argued that the period-function ( .()
) has separate (localalized) "ownership" by bquote
and plyr functions. And to my point, redefining c()
is also a really bad idea.– 42-
Oct 9 '14 at 3:02
15
15
@BondedDust But let's say that
data.table
wanted to define ~=
as new infix operator. They cannot do that because the parser would not recognize it (ie parse(text="a~=3")
would generate an error). The "specialness" of :=
is completely independent of the the data.table
package. It is a big exception to the rule that custom infix operators require %
which seems to be the spirit of the OP's question as I read it.– MrFlick
Oct 9 '14 at 3:07
@BondedDust But let's say that
data.table
wanted to define ~=
as new infix operator. They cannot do that because the parser would not recognize it (ie parse(text="a~=3")
would generate an error). The "specialness" of :=
is completely independent of the the data.table
package. It is a big exception to the rule that custom infix operators require %
which seems to be the spirit of the OP's question as I read it.– MrFlick
Oct 9 '14 at 3:07
3
3
+1 Nice job digging into the source!
– Joshua Ulrich
Oct 9 '14 at 15:19
+1 Nice job digging into the source!
– Joshua Ulrich
Oct 9 '14 at 15:19
1
1
I'm guessing at some point R Core was thinking of implementing
:=
as an alternative to <-
since some languages use that as the assignment operator, but then dropped the idea after the parser was written.– BrodieG
Apr 19 '17 at 22:03
I'm guessing at some point R Core was thinking of implementing
:=
as an alternative to <-
since some languages use that as the assignment operator, but then dropped the idea after the parser was written.– BrodieG
Apr 19 '17 at 22:03
|
show 4 more comments
It's not just a colon operator but rather :=
is a single operator formed by the colon and equal sign (just as the combination of "<" and "-" forms the assignment operator in base R). The :=
operator is an infix function that is defined to be part of the evaluation of the "j" argument inside the [.data.table
function. It creates or assigns a value to a column designated by its LHS argument using the result of evaluating its RHS.
4
To the downvoters who are not explaining their concerns. This answer was written to respond to the question as originally written. You can see its original title and content by clicking on the "edited ...." link.
– 42-
Oct 9 '14 at 17:39
add a comment |
It's not just a colon operator but rather :=
is a single operator formed by the colon and equal sign (just as the combination of "<" and "-" forms the assignment operator in base R). The :=
operator is an infix function that is defined to be part of the evaluation of the "j" argument inside the [.data.table
function. It creates or assigns a value to a column designated by its LHS argument using the result of evaluating its RHS.
4
To the downvoters who are not explaining their concerns. This answer was written to respond to the question as originally written. You can see its original title and content by clicking on the "edited ...." link.
– 42-
Oct 9 '14 at 17:39
add a comment |
It's not just a colon operator but rather :=
is a single operator formed by the colon and equal sign (just as the combination of "<" and "-" forms the assignment operator in base R). The :=
operator is an infix function that is defined to be part of the evaluation of the "j" argument inside the [.data.table
function. It creates or assigns a value to a column designated by its LHS argument using the result of evaluating its RHS.
It's not just a colon operator but rather :=
is a single operator formed by the colon and equal sign (just as the combination of "<" and "-" forms the assignment operator in base R). The :=
operator is an infix function that is defined to be part of the evaluation of the "j" argument inside the [.data.table
function. It creates or assigns a value to a column designated by its LHS argument using the result of evaluating its RHS.
answered Oct 9 '14 at 2:56
42-42-
213k15260401
213k15260401
4
To the downvoters who are not explaining their concerns. This answer was written to respond to the question as originally written. You can see its original title and content by clicking on the "edited ...." link.
– 42-
Oct 9 '14 at 17:39
add a comment |
4
To the downvoters who are not explaining their concerns. This answer was written to respond to the question as originally written. You can see its original title and content by clicking on the "edited ...." link.
– 42-
Oct 9 '14 at 17:39
4
4
To the downvoters who are not explaining their concerns. This answer was written to respond to the question as originally written. You can see its original title and content by clicking on the "edited ...." link.
– 42-
Oct 9 '14 at 17:39
To the downvoters who are not explaining their concerns. This answer was written to respond to the question as originally written. You can see its original title and content by clicking on the "edited ...." link.
– 42-
Oct 9 '14 at 17:39
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.
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%2f26269423%2fwhy-is-allowed-as-an-infix-operator%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
5
Please take a look at the data.table documentation, starting maybe with the FAQ.
– Dirk Eddelbuettel
Oct 9 '14 at 2:39
1
@DirkEddelbuettel. I understand how it's used in data.table. But the fact that R allows for such an operator to be defined and not cause a syntax error is what intrigued me. It's a fundamental question about R and maybe how it parses code.
– xiaodai
Oct 9 '14 at 2:44
2
AFAIK it is local to data.table and only works with the
[
subsetting. So your question is off-base (not an R quirk) which is why I sent you to the data.table docs which discuss this.– Dirk Eddelbuettel
Oct 9 '14 at 2:49
1
@DirkEddelbuettel I think you are missing my point. I can define a funciton using
:=
<- function(a,b) paste(a,b); and I can use it by doing "abc" := "def"! But all other infix function are in the form of %in.fn%?. Why?– xiaodai
Oct 9 '14 at 2:57
2
This Q&A from Matt might be very relevant here as well.
– Arun
Oct 9 '14 at 6:51