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

Fix R reading files #11436

Open
kcrisman opened this issue Jun 7, 2011 · 7 comments
Open

Fix R reading files #11436

kcrisman opened this issue Jun 7, 2011 · 7 comments

Comments

@kcrisman
Copy link
Member

kcrisman commented Jun 7, 2011

The current way we configure the R Pexpect interface is to have a 1024 character cutoff to trying to read from a file.

Problem: this doesn't actually seem to work.


    sage: s = 'matrix(c(1, 1, 1, 1,' + ' '*987 + '2,2,2,2), ncol=4)' 
    sage: len(s) 
    1024 
    sage: r.eval(s) 
    '     [,1] [,2] [,3] [,4]\n[1,]    1    1    2    2\n[2,]    1    1     
2    2' 
    sage: s = 'matrix(c(1, 1, 1, 1,' + ' '*988 + '2,2,2,2), ncol=4)' 
    sage: len(s) 
    1025 
    sage: r.eval(s) 
    '' 

jhpalmieri helped track this down. See this sage-support thread for more details.

Helpful links:

It seems like everything is creating files as should be, and using the verbose option to source shows that at least something's being computed, but the result is not showing up in Sage, possibly due to misuse of "source", or "file".

CC: @jhpalmieri @jasongrout @williamstein

Component: interfaces

Keywords: r-project

Author: Karl-Dieter Crisman

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

@kcrisman
Copy link
Member Author

kcrisman commented Jun 7, 2011

comment:1

In fact, the file part of what we use doesn't even seem to be necessary. The option we need is print.eval=TRUE.

sage: r.eval('source(file="/Users/.../48141//interface//tmp48141",local=TRUE)')
''
sage: r.eval('source(file="/Users/.../48141//interface//tmp48141",print.eval=TRUE)')
'[1] 1 2 3'

@kcrisman
Copy link
Member Author

kcrisman commented Jun 7, 2011

comment:2

Yes, and this fixes the original problem too.

The only issue is that


        """
        Reads filename into the R interpreter by calling R's source function on a
        read-only file connection.

        EXAMPLES:
            sage: filename = tmp_filename()
            sage: f = open(filename, 'w')
            sage: f.write('a <- 2+2\n')
            sage: f.close()
            sage: r.read(filename)
            sage: r.get('a')
            '[1] 4'
        """

So the idea is perhaps that we do NOT see the output from such an evaluation. The problem is that then one has to know that one should assign the big computation to a name via variable <- command, and that is not obvious.

What is the best solution here? To change the reading of lines or to make the documentation REALLY clear? My preference would be to have long commands still output, just like short commands; it seems unfair to have them suddenly do this.

@kcrisman
Copy link
Member Author

kcrisman commented Jun 7, 2011

Based on 4.4.4, but hopefully still applies...

@kcrisman
Copy link
Member Author

kcrisman commented Jun 7, 2011

comment:3

Attachment: trac_11436.patch.gz

Possible patch uploaded. Probably needs more documentation, but it fixed my problem locally so I'm going to bed. Suggestions welcome.

@kcrisman
Copy link
Member Author

kcrisman commented Jun 7, 2011

Author: Karl-Dieter Crisman

@kcrisman
Copy link
Member Author

Changed keywords from none to r-project

@kcrisman
Copy link
Member Author

comment:5

See this sage-devel thread for what I believe is this same problem.

@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
@mkoeppe mkoeppe removed this from the sage-6.4 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

4 participants