I am curious if anyone knows of R code where the "{" function is redefined in a useful way. Or "(" for that matter. Thanks Mick
On 17 Apr 2015, at 06:19 , Mick Jordan <mick.jordan at oracle.com> wrote:> I am curious if anyone knows of R code where the "{" function is redefined in a useful way. Or "(" for that matter.I sincerely would hope not.... Incidentally, I seem to recall that during the design of (new?) S, it was at some point the intention to specify vectors as (7, 9, 13) or [7, 9, 13] but the resulting semantic issues led the developers to choose the pure functional form c(7, 9, 13). -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
One could redefine the "{" function with something like `{` <- function(...) simplify2array(list(...)) but then you would have to live with the syntax it requires (semicolons for separators instead of commas) > {1; 2; 3} [1] 1 2 3 > {{11;12;13}; {21;22;23}; {31;32;33}} [,1] [,2] [,3] [1,] 11 21 31 [2,] 12 22 32 [3,] 13 23 33 I have not seen this in any "real" code. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Apr 16, 2015 at 9:19 PM, Mick Jordan <mick.jordan at oracle.com> wrote:> I am curious if anyone knows of R code where the "{" function is redefined > in a useful way. Or "(" for that matter. > > Thanks > Mick > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
Redefining operators can be useful in translating R syntax to some other language. E.g., dplyr does that sort of thing to translate to sql. It puts the altered definition into an environment that is used only for such translation so it doesn't mess up other functions. > dplyr::base_scalar$`{` function (x) { build_sql("(", x, ")") } <environment: namespace:dplyr> Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Apr 17, 2015 at 7:49 AM, William Dunlap <wdunlap at tibco.com> wrote:> One could redefine the "{" function with something like > `{` <- function(...) simplify2array(list(...)) > but then you would have to live with the syntax it requires > (semicolons for separators instead of commas) > > {1; 2; 3} > [1] 1 2 3 > > {{11;12;13}; {21;22;23}; {31;32;33}} > [,1] [,2] [,3] > [1,] 11 21 31 > [2,] 12 22 32 > [3,] 13 23 33 > > I have not seen this in any "real" code. > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Thu, Apr 16, 2015 at 9:19 PM, Mick Jordan <mick.jordan at oracle.com> > wrote: > >> I am curious if anyone knows of R code where the "{" function is >> redefined in a useful way. Or "(" for that matter. >> >> Thanks >> Mick >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> > >[[alternative HTML version deleted]]