RProvider icon indicating copy to clipboard operation
RProvider copied to clipboard

Need to release bindings created when calling functions

Open hmansell opened this issue 13 years ago • 4 comments

Currently, bindings are set in R forever and never released

hmansell avatar Jul 31 '12 13:07 hmansell

This may be a non-starter for performance (or other) reasons, but I wonder if you've considered changing callFunc so that it evals an anonymous function with the real call as the body and the generated symbols as formal parameters, then invoking the anonymous function with the appropriate values as arguments (i.e., modeling a let using a lambda). It seems like this would eliminate the need for the top-level bindings.

glchapman avatar Jan 15 '14 00:01 glchapman

Can you elaborate on what you expect that to achieve? Are you talking about the top-level bindings in R? They are needed to pass argument values through (in cases where they cannot be robustly passed through as literals.

hmansell avatar Jan 15 '14 23:01 hmansell

Here's what I had in mind. I changed RInterop so that it still generates tempSymbols, but no longer regsters then with the Engine. I then changed the end of callFunc to

    let callargs = String.Join(", ", argList)
    if tempSymbols.Count = 0 then
        let expr = sprintf "%s::`%s`(%s)" packageName funcName callargs
        eval expr
    else
        let formals = String.Join(", ", Seq.map fst tempSymbols)
        let expr = sprintf "function(%s) {%s::`%s`(%s)}" formals packageName funcName callargs
        let func = (eval expr).AsFunction()
        func.Invoke(Seq.map snd tempSymbols |> Seq.toArray)

I haven't run into any problems with this change so far, but I've not extensively tested it nor have I tried to measure performance.

glchapman avatar Jan 16 '14 00:01 glchapman

OK, I think I understand, but a pull-request with fully working code would make it easier to follow.

Does this with with varargs (... args in R)? It's important that those get passed, and the specified name is passed too (for example, when constructing something like a data.frame).

hmansell avatar Jan 16 '14 13:01 hmansell