Displaying 14 results from an estimated 14 matches for "init_matrices".
2023 Mar 11
1
Multiple Assignment built into the R Interpreter?
...e of the language itself.
Given that the other 3 major scientific computing languages (Matlab, Python
and Julia) have implemented it very successfully,
I don't think the general practicality of it should be an issue. Regarding
implementation in other languages, Julia works as follows:
function init_matrices()
A = 1; C = 2; Q = 3; R = 4
return A, C, Q, R
end
res = init_matrices() # gives a Julia Tuple (A, C, Q, R)
A, C = init_matrices() # Works, A is 1, C is 2, the others are
dropped
A, C, Q, R = init_matrices() # Standard
I think as far as R is concerned multiple retur...
2023 Mar 11
1
Multiple Assignment built into the R Interpreter?
I think the standard way to do this in R is given by list2env(), as
described in a couple of answers on the SO page you linked.
The syntax you proposed would be likely to be confusing in complex
expressions, e.g.
f(A, C, Q, R = init_matrices(X, Y, Z))
would obviously not work but wouldn't trigger a syntax error, and
f((A, C, Q, R = init_matrices(X, Y, Z)))
could work, but looks too much like the previous one. So I think R
would want Javascript-like
[A, C, Q, R] <- init_matrices(X, Y, Z)
instead. But then the questi...
2023 Mar 11
1
Multiple Assignment built into the R Interpreter?
...e is still a performance cost to it, in my
> case a call to
> .Call() and parent.frame(), which is quite low, but still high compared
> to the cost of `<-` or `=`.
Another R way to do what you're doing would be to stay within a list the
whole time, i.e. code it as
mats <- init_matrices(X, Y, Z)
with(mats, ... do things with A, C, Q, and R ... )
This won't give warnings about globals, and it makes very clear that
those 4 matrices are all closely related, and it allows you to work with
multiple 4-tuples of matrices, etc.
> So what I am requesting is indeed nothing les...
2023 Mar 11
3
Multiple Assignment built into the R Interpreter?
...R Core,
working on my dynamic factor modelling package, which requires several
subroutines to create and update several system matrices, I come back to
the issue of being annoyed by R not supporting multiple assignment out of
the box like Matlab, Python and julia. e.g. something like
A, C, Q, R = init_matrices(X, Y, Z)
would be a great addition to the language. I know there are several
workarounds such as the %<-% operator in the zeallot package or my own %=%
operator in collapse, but these don't work well for package development as
R CMD Check warns about missing global bindings for the created...
2023 Mar 11
3
Multiple Assignment built into the R Interpreter?
...can and Ivan for the careful thoughts. I'm not sure I can follow
all aspects you raised, but to give my limited take on a few:
> your proposal violates a very basic property of the language, i.e. that all statements are expressions and have a value.
> What's the value of 1 + (A, C = init_matrices()).
I'm not sure I see the point here. I evaluated 1 + (d = dim(mtcars);
nr = d[1]; nc = d[2]; rm(d)), which simply gives a syntax error, as
the above expression should. `%=%` assigns to
environments, so 1 + (c("A", "C") %=% init_matrices()) returns
numeric(0), with A and...
2023 Mar 11
1
Multiple Assignment built into the R Interpreter?
...the careful thoughts. I'm not sure I can
> follow all aspects you raised, but to give my limited take on a few:
>
>> your proposal violates a very basic property of the language, i.e. that all statements are expressions and have a value. > What's the value of 1 + (A, C = init_matrices()).
>
> I'm not sure I see the point here. I evaluated 1 + (d = dim(mtcars); nr
> = d[1]; nc = d[2]; rm(d)), which simply gives a syntax error,
d = dim(mtcars); nr = d[1]; nc = d[2]; rm(d)
is not a statement, it is a sequence of 4 statements.
Duncan Murdoch
as the
> abov...
2023 Mar 11
2
Multiple Assignment built into the R Interpreter?
...thoughts. I'm not sure I can
> > follow all aspects you raised, but to give my limited take on a few:
> >
> >> your proposal violates a very basic property of the language, i.e. that all statements are expressions and have a value. > What's the value of 1 + (A, C = init_matrices()).
> >
> > I'm not sure I see the point here. I evaluated 1 + (d = dim(mtcars); nr
> > = d[1]; nc = d[2]; rm(d)), which simply gives a syntax error,
>
>
> d = dim(mtcars); nr = d[1]; nc = d[2]; rm(d)
>
> is not a statement, it is a sequence of 4 statements....
2023 Mar 12
2
Multiple Assignment built into the R Interpreter?
...e I can
> > > follow all aspects you raised, but to give my limited take on a few:
> > >
> > >> your proposal violates a very basic property of the language, i.e.
> that all statements are expressions and have a value. > What's the value
> of 1 + (A, C = init_matrices()).
> > >
> > > I'm not sure I see the point here. I evaluated 1 + (d = dim(mtcars); nr
> > > = d[1]; nc = d[2]; rm(d)), which simply gives a syntax error,
> >
> >
> > d = dim(mtcars); nr = d[1]; nc = d[2]; rm(d)
> >
> > is not a state...
2023 Mar 11
1
Multiple Assignment built into the R Interpreter?
...eful thoughts. I'm not sure I can follow
> all aspects you raised, but to give my limited take on a few:
>
> > your proposal violates a very basic property of the language, i.e. that
> all statements are expressions and have a value.
> > What's the value of 1 + (A, C = init_matrices()).
>
> I'm not sure I see the point here. I evaluated 1 + (d = dim(mtcars);
> nr = d[1]; nc = d[2]; rm(d)), which simply gives a syntax error, as
> the above expression should. `%=%` assigns to
> environments, so 1 + (c("A", "C") %=% init_matrices()) returns...
2023 Mar 11
1
Multiple Assignment built into the R Interpreter?
On 11/03/2023 11:57 a.m., Ivan Krylov wrote:
> On Sat, 11 Mar 2023 11:11:06 -0500
> Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>
>> That's clear, but your proposal violates a very basic property of the
>> language, i.e. that all statements are expressions and have a value.
>
> How about reframing this feature request from multiple assignment
>
2023 Mar 12
1
Multiple Assignment built into the R Interpreter?
...aised, but to give my limited take
> on a few:
> > >
> > >> your proposal violates a very basic property of the
> language, i.e. that all statements are expressions and have a
> value.? > What's the value of 1 + (A, C = init_matrices()).
> > >
> > > I'm not sure I see the point here. I evaluated 1 + (d =
> dim(mtcars); nr
> > > = d[1]; nc = d[2]; rm(d)), which simply gives a syntax error,
> >
> >
> >? ? d = dim(mtca...
2023 Mar 12
1
Multiple Assignment built into the R Interpreter?
...mited take
> > on a few:
> > > >
> > > >> your proposal violates a very basic property of the
> > language, i.e. that all statements are expressions and have a
> > value. > What's the value of 1 + (A, C = init_matrices()).
> > > >
> > > > I'm not sure I see the point here. I evaluated 1 + (d =
> > dim(mtcars); nr
> > > > = d[1]; nc = d[2]; rm(d)), which simply gives a syntax
> error,
> > >
> > >...
2023 Mar 13
1
Multiple Assignment built into the R Interpreter?
...gt; ???????? > >
> > > ???????? > >> your proposal violates a very basic property of the
> > > ??????? language, i.e. that all statements are expressions and
> > > have a
> > > ??????? value.? > What's the value of 1 + (A, C =
> > > init_matrices()).
> > > ???????? > >
> > > ???????? > > I'm not sure I see the point here. I evaluated 1 +
> > > (d =
> > > ??????? dim(mtcars); nr
> > > ???????? > > = d[1]; nc = d[2]; rm(d)), which simply gives a
> > > syntax
> >...
2023 Mar 13
1
Multiple Assignment built into the R Interpreter?
...> >
>>>> ???????? > >> your proposal violates a very basic property of the
>>>> ??????? language, i.e. that all statements are expressions and
>>>> have a
>>>> ??????? value.? > What's the value of 1 + (A, C =
>>>> init_matrices()).
>>>> ???????? > >
>>>> ???????? > > I'm not sure I see the point here. I evaluated 1 +
>>>> (d =
>>>> ??????? dim(mtcars); nr
>>>> ???????? > > = d[1]; nc = d[2]; rm(d)), which simply gives a
>>>>...