Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R interface: fix passing strings #2963

Open
mwhansen opened this issue Apr 20, 2008 · 3 comments
Open

R interface: fix passing strings #2963

mwhansen opened this issue Apr 20, 2008 · 3 comments

Comments

@mwhansen
Copy link
Contributor

One should be able to do

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

instead of

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

Component: interfaces

Issue created by migration from https://trac.sagemath.org/ticket/2963

@mwhansen mwhansen added this to the sage-5.11 milestone Apr 20, 2008
@mwhansen mwhansen self-assigned this Apr 20, 2008
@simon-king-jena
Copy link
Member

comment:1

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

@simon-king-jena
Copy link
Member

comment:2

Replying to @simon-king-jena:

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

@kcrisman
Copy link
Member

comment:3

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.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@jdemeyer jdemeyer changed the title make it so that strings pass as arguments and keyword arguments for the expect interfaces are passed down as string. R interface: fix passing strings Jun 23, 2015
@jdemeyer jdemeyer modified the milestones: sage-6.4, sage-6.8 Jun 23, 2015
@mkoeppe mkoeppe removed this from the sage-6.8 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants