The condition is true all the way until you index outside the vector...
Cheers
On 31 Mar 2018, 17.29 +0200, Henri Moolman , wrote:
> Could you please provide help with something from R that I find rather
> puzzling? In the small program below x[1]=1, . . . , x[5]=5. R
mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> > On Tue, Feb 27, 2018 at 6:51 AM, Thomas Mailund <thomas.mail...@gmail.com>
> > wrote:
> > > Interestingly,
76.3949 977.6235 1042.5035
2889.779 100
factorial_tr_manual(1000) 110.215 116.919 130.2337 118.7350 122.7495
255.062 100
factorial_tr_automatic_1(1000) 179.897 183.437 212.8879 187.8250 195.7670
979.352 100
factorial_tr_automatic_2(1000) 508.353 534.328 601.9643 560.7830
limit
> llength_tr(make_llist(1000))
[1] 1000
I should be able to make the function go faster if I had a faster way of
handling the variable assignments, but inside “with”, I’m not sure how to do
that…
Any suggestions?
Cheers
On 11 Feb 2018, 16.48 +0100, Thomas Mailund <thomas.mail...@gmai
. It might be doable with
JIT or something like that, but my goal is less ambitious.
Using local, though, might be an approach. I will play around with that
tomorrow.
Cheers
On 11 Feb 2018, 18.19 +0100, David Winsemius <dwinsem...@comcast.net>, wrote:
>
> > On Feb 11, 2018, at 7:48 AM,
Hi guys,
I am working on some code for automatically translating recursive functions
into looping functions to implemented tail-recursion optimisations. See
https://github.com/mailund/tailr
As a toy-example, consider the factorial function
factorial <- function(n, acc = 1) {
if (n <= 1)
Do you mean like this?
> f <- function(foo, bar) {
+ result <- list(bar)
+ names(result) <- foo
+ result
+ }
> (x <- f("hello", "world"))
$hello
[1] "world"
> names(x)
[1] "hello"
--
Thomas Mailund
On 4 August 2017 at
The order the bars are plotted in is determined by the levels in a factor, and
your labels are treated as a factor. You can make sure you keep the order of
your labels by simply doing this:
Lab <- factor(Lab, levels = Lab)
before constructing the data frame.
Cheers
On 27 Jun 2017, 20.43
and persistent data structures to implement queues
http://www.westpoint.edu/eecs/SiteAssets/SitePages/Faculty%20Publication%20Documents/Okasaki/jfp95queue.pdf
Cheers
On 24 Apr 2017, 16.35 +0200, Thomas Mailund <thomas.mail...@gmail.com>, wrote:
> Hi, I’m playing around with ways of
If you write something like
indices <- rep(1:(163863/6069), each = 6069)
you can get the i’th block of rows with
table[indices == i,]
It looks like a little more work than a loop would be since you have to run
through all rows for each block, but the implicit loop in this approach is
likely
Hi, I’m playing around with ways of implementing lazy evaluation of
expressions. In R, function arguments are evaluated as promises but expressions
are evaluated immediately, so I am trying to wrap expressions in
thunks—functions with no arguments that evaluate an expression—to get something
f slow. It is why everybody yells 'vectorize' and 'use lapply'
> all the time. Then again, I'm guessing because I dont understand your code:)
>
> Good luck,
> PJ
>
>
>
>
> On Apr 11, 2017 7:44 PM, "Thomas Mailund" <thomas.mail...@gmail.com
> (mailto:t
Hi y’all,
I’m working on a book on how to implement functional data structures in R, and
in particular on a chapter on implementing queues. You get get the current
version here https://www.dropbox.com/s/9c2yk3a67p1ypmr/book.pdf?dl=0 and the
relevant pages are 50-59. I’ve implemented three
10, 2017 4:04 AM, "Thomas Mailund"
<mail...@birc.au.dk<mailto:mail...@birc.au.dk>> wrote:
You can get that using `formals()`.
my_func <- function(dataset = iris)
{
#print(dataset) # here I do not want to print the dataset but the name
# of the object - iris in this
You can get that using `formals()`.
my_func <- function(dataset = iris)
{
#print(dataset) # here I do not want to print the dataset but the name
# of the object - iris in this case - instead
print(formals()$dataset) # this is what you want
}
This gives you what the arguments were
of packages, since the ones
you have installed for version 3.2 R won't be available in the 3.3
installation, but *those* packages you can install using install.packages.
Cheers
--
Thomas Mailund
On 22 August 2016 at 22:17:50, KMNanus
(kmna...@gmail.com<mailto:kmna...@gmail.com>) wrote
The nested for-loops could very easily be moved to Rcpp which should speed them
up. Using apply functions instead of for-loops will not make it faster; they
still have to do the same looping.
At least, when I use `outer` to replace the loop I get roughly the same speed
for the two versions
Hi Ivan,
ls() inside a function gives you the variables in the local scope. If you want
to get the variables defined in the global scope you need to tell ls() that.
Check the difference between these three functions:
> foo <- function() ls()
> foo()
Returns character(0) because there are no
say to that :)
Cheers
Thomas
On 11 August 2016 at 23:05:29, Duncan Murdoch
(murdoch.dun...@gmail.com<mailto:murdoch.dun...@gmail.com>) wrote:
On 10/08/2016 1:28 PM, Duncan Murdoch wrote:
> On 10/08/2016 1:10 PM, Thomas Mailund wrote:
>> That did the trick!
>>
>> I wa
10/08/2016 2:39 PM, Thomas Mailund wrote:
Ok, I think maybe I am beginning to see what is going wrong...
Explicitly remembering the thunk parameters in a list works fine, as far as I
can see.
make_thunk <- function(f, ...) {
remembered <- list(...)
function(...) do.call(f, as.lis
ct?
Now why I can still get it to work when I call `cat` remains a mystery…
Cheers
Thomas
On 10 August 2016 at 19:12:41, Thomas Mailund
(mail...@birc.au.dk(mailto:mail...@birc.au.dk)) wrote:
>
> That did the trick!
>
> I was so focused on not evaluating the continuati
Well, they stay at 3 when I call cat (except for the final step going down in
they recursion where `identity` is called, where they are 4). They do that both
when I evaluate ... in the `make_thunk` function and when I don’t. But then,
when I call `cat` it also worked before. I cannot keep
> On 10/08/2016 1:10 PM, Thomas Mailund wrote:
> > That did the trick!
> >
> > I was so focused on not evaluating the continuation that I completely
> > forgot that the thunk could hold an unevaluated value… now it seems to be
> > working for all the
On 10 Aug 2016, at 19:15, Bert Gunter
> wrote:
make_thunk is probably unnecessary and apparently problematic. I think
you could use do.call() instead, as do.call(f,list(...)) .
Yes,
make_thunk <- function(f, ...) function() do.call(f,
But wait, how is it actually changing? And how did calling `cat` make the
problem go away?
Ok, I will go think about it…
Thanks anyway, it seems to do the trick.
> On 10 Aug 2016, at 19:10, Thomas Mailund <mail...@birc.au.dk> wrote:
>
>
> That did the trick!
>
* the forced evaluation is
necessary there, but I will figure that out when my tired brain has had a
little rest.
Thanks a lot!
Thomas
> On 10 Aug 2016, at 19:04, Duncan Murdoch <murdoch.dun...@gmail.com> wrote:
>
> On 10/08/2016 12:53 PM, Thomas Mailund wrote:
>> &g
ut the text inside it. Removing the
`cat` line and I get the recursion error…
Cheers
Thomas
> On 10 Aug 2016, at 18:53, Thomas Mailund <mail...@birc.au.dk> wrote:
>
>
>> On 10 Aug 2016, at 13:56, Thomas Mailund <mail...@birc.au.dk> wrote:
>>
>
> On 10 Aug 2016, at 13:56, Thomas Mailund <mail...@birc.au.dk> wrote:
>
> make_thunk <- function(f, ...) f(...)
Doh! It is of course this one:
make_thunk <- function(f, ...) function() f(…)
It just binds a function call into a thunk so I can delay its evaluation.
Oh, I see that the make_thunk function is missing in my example. It is just
this one
make_thunk <- function(f, ...) f(...)
On 9 August 2016 at 21:57:05, Thomas Mailund
(mail...@birc.au.dk(mailto:mail...@birc.au.dk)) wrote:
> [I’m really sorry if you receive this mail twice.
[I’m really sorry if you receive this mail twice. I just noticed I had sent it
from a different account that the one I signed up to the mailing list on and I
don’t know if that means it will be filtered; at least I haven’t received it
myself yet.]
I am playing around with continuation-passing
30 matches
Mail list logo