Opened 10 years ago

Last modified 2 years ago

#2963 new enhancement

R interface: fix passing strings

Reported by: mhansen Owned by: mhansen
Priority: major Milestone: sage-6.8
Component: interfaces Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

One should be able to do

r.png(file="myplot3.png")

instead of

sage: r.png(file='"myplot3.png"')

Change History (8)

comment:1 follow-up: Changed 8 years ago by SimonKing

Hi Mike!

Just a quick idea: Couldn't one simply do

    def png(self, *args, **kwds):
        ...
        f = lambda x: x if not isinstance(x,basestring) else ('%s'%x if x[0]==x[-1]=='"' else '"%s"'%x)
        return RFunction(self, 'png')(*[f(x) for x in args], **dict([(x,f(y)) for x,y in kwds.items()]))

This would transform any string into a '"string"', unless string starts and ends with '"' already, and any other input is untouched. In particular, my suggestion would not break existing code, since r.png(file='"myplot3.png"') would still be valid.

I don't know in what way png is usually called: Frequently and with many arguments? Then my suggestion might involve a performance problem. Also I don't know if the application of f to args is needed as well, or if the application to kwds would be enough.

Regards,

Simon

comment:2 in reply to: ↑ 1 Changed 8 years ago by SimonKing

Replying to SimonKing:

I don't know in what way png is usually called: Frequently and with many arguments? Then my suggestion might involve a performance problem. Also I don't know if the application of f to args is needed as well, or if the application to kwds would be enough.

Sorry, perhaps I misunderstood the role of png: It is just one example, isn't it? But actually you want that in all expect interfaces the transition from 'bla' to '"bla"' is done, right? Then still my suggestion would solve the problem, but I guess the above lambda function should be defined in expect.py on module level, so that there is no need to create the function over and over again.

Then, one would go through all methods of all expect interfaces, and do changes to the arguments, if they might be strings. Wow, that would be much to do! And then I don't know how much performance regression would occur and if that price would be worth to pay for making the input more comfortable.

Cheers, Simon

comment:3 Changed 5 years ago by kcrisman

  • Report Upstream set to N/A

See also #12948, as many many people have asked how to do this in R and we still don't really have a nice solution for this in general.

comment:4 Changed 4 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:5 Changed 4 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:6 Changed 3 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:7 Changed 3 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:8 Changed 2 years ago by jdemeyer

  • Milestone changed from sage-6.4 to sage-6.8
  • Summary changed from make it so that strings pass as arguments and keyword arguments for the expect interfaces are passed down as string. to R interface: fix passing strings
Note: See TracTickets for help on using tickets.