[IPython-dev] cell magics
Jason Grout
jason-sage at creativetrax.com
Sat Feb 16 20:26:28 EST 2013
On 2/16/13 6:38 PM, Thomas Kluyver wrote:
> On 17 February 2013 00:14, Jason Grout <jason-sage at creativetrax.com
> <mailto:jason-sage at creativetrax.com>> wrote:
>
> Cool. I didn't know that. But if k was a list (for some other
> parameter), and you were trying to sub it in, you'd have to convert the
> list to a string, then convert it back in the decorator. That's a
> little silly.
>
>
> In theory, but I don't think we've ever had such a case. The %%R magic
> has something roughly similar - you can pass in variables including
> arrays, like
>
> %%R -i myvar
> code...
>
> In that case, the magic looks in the namespaces for 'myvar', so it
> doesn't have to be converted to a string and back. Arguably you could
> pull the variable in more elegantly with your proposal, something like:
>
> %R(input=[myvar])
> code
>
> But we also use the name to assign the converted variable to in R, so
> you'd need to provide that separately:
>
> %R(input={'myvar':myvar})
> code
>
> That is slightly more flexible, but most of the time it's going to
> involve unnecessary repetition, in addition to the extra punctuation.
>
If you were going to use the name and the value, it would make sense to do:
%R(input=['myvar'])
or even
%R(input='myvar')
-Jason
More information about the IPython-dev
mailing list