Ticket #12057: trac_12057_fix_doctests.patch

File trac_12057_fix_doctests.patch, 7.6 KB (added by vbraun, 11 years ago)

Minor docstring fix.

  • sage/interfaces/r.py

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1321906436 0
    # Node ID 9d5ffb2a960288ed69b7078338fc8c0e38af9092
    # Parent  9276337e5cd9643ceb185388014bd03858b4cb86
    Trac #12057: Fix doctests related to R upgrade
    
    diff --git a/sage/interfaces/r.py b/sage/interfaces/r.py
    a b  
    1111The simplest data structure in R is the numeric vector which
    1212consists of an ordered collection of numbers.  To create a
    1313vector named $x$ using the R interface in Sage, you pass the
    14 R interpreter object a list or tuple of numbers.
     14R interpreter object a list or tuple of numbers::
     15
    1516    sage: x = r([10.4,5.6,3.1,6.4,21.7]); x
    1617    [1] 10.4  5.6  3.1  6.4 21.7
    1718
    1819You can invert elements of a vector x in R by using the
    19 invert operator or by doing 1/x.
     20invert operator or by doing 1/x::
     21
    2022    sage: ~x
    2123    [1] 0.09615385 0.17857143 0.32258065 0.15625000 0.04608295
    2224    sage: 1/x
    2325    [1] 0.09615385 0.17857143 0.32258065 0.15625000 0.04608295
    2426
    2527The following assignment creates a vector $y$ with 11 entries which
    26 consists of two copies of $x$ with a 0 in between.
     28consists of two copies of $x$ with a 0 in between::
     29
    2730    sage: y = r([x,0,x]); y
    2831    [1] 10.4  5.6  3.1  6.4 21.7  0.0 10.4  5.6  3.1  6.4 21.7
    2932
     
    3134
    3235The following command generates a new vector $v$ of length 11 constructed
    3336by adding together (element by element) $2x$ repeated 2.2 times, $y$
    34 repeated just once, and 1 repeated 11 times.
     37repeated just once, and 1 repeated 11 times::
     38
    3539    sage: v = 2*x+y+1; v
    3640    [1] 32.2 17.8 10.3 20.2 66.1 21.8 22.6 12.8 16.9 50.8 43.5
    3741
    3842One can compute the sum of the elements of an R vector in the following
    39 two ways:
     43two ways::
     44
    4045    sage: sum(x)
    4146    [1] 47.2
    4247    sage: x.sum()
    4348    [1] 47.2
    4449
    45 One can calculate the sample variance of a list of numbers:
     50One can calculate the sample variance of a list of numbers::
     51
    4652    sage: ((x-x.mean())^2/(x.length()-1)).sum()
    4753    [1] 53.853
    4854    sage: x.var()
    4955    [1] 53.853
    5056
    51    
    5257    sage: x.sort()
    5358    [1] 3.1  5.6  6.4 10.4 21.7
    5459    sage: x.min()
     
    5863    sage: x
    5964    [1] 10.4  5.6  3.1  6.4 21.7
    6065
    61 
    62 
    6366    sage: r(-17).sqrt()
    6467    [1] NaN
    6568    sage: r('-17+0i').sqrt()
    6669    [1] 0+4.123106i
    6770
    68 Generating Regular Sequences
     71Generating an arithmetic sequence::
    6972
    7073    sage: r('1:10')
    7174    [1] 1  2  3  4  5  6  7  8  9 10
    7275
    7376Because 'from' is a keyword in Python, it can't be used
    7477as a keyword argument.  Instead, 'from_' can be passed, and
    75 R will recognize it as the correct thing. 
     78R will recognize it as the correct thing::
     79
    7680    sage: r.seq(length=10, from_=-1, by=.2)
    7781    [1] -1.0 -0.8 -0.6 -0.4 -0.2  0.0  0.2  0.4  0.6  0.8
    7882
     
    8488    sage: x.rep(each=2)
    8589    [1] 10.4 10.4  5.6  5.6  3.1  3.1  6.4  6.4 21.7 21.7
    8690
    87 Missing Values
     91Missing Values::
     92
    8893    sage: na = r('NA')
    8994    sage: z = r([1,2,3,na])
    9095    sage: z
     
    114119    [1] FALSE
    115120   
    116121
    117 Character Vectors
     122Character Vectors::
    118123
    119124    sage: labs = r.paste('c("X","Y")', '1:10', sep='""'); labs
    120125    [1] "X1"  "Y2"  "X3"  "Y4"  "X5"  "Y6"  "X7"  "Y8"  "X9"  "Y10"
    121126
    122127
    123 Index vectors; selecting and modifying subsets of a data set
     128Index vectors; selecting and modifying subsets of a data set::
    124129
    125130    sage: na = r('NA')
    126131    sage: x = r([10.4,5.6,3.1,6.4,21.7,na]); x
     
    128133    sage: x['!is.na(self)']
    129134    [1] 10.4  5.6  3.1  6.4 21.7
    130135   
    131    
    132136    sage: x = r([10.4,5.6,3.1,6.4,21.7,na]); x
    133137    [1] 10.4  5.6  3.1  6.4 21.7   NA
    134138    sage: (x+1)['(!is.na(self)) & self>0']
     
    138142    sage: (x+1)['(!is.na(self)) & self>0']
    139143    [1] 11.4  4.1  0.5 22.7
    140144
    141 Distributions
     145Distributions::
    142146
    143147    sage: r.options(width="60");
    144148    $width
     
    163167    [57] 0.013582969 0.010420935 0.007915452 0.005952532
    164168    [61] 0.004431848
    165169
    166 Convert R Data Structures to Python/Sage
     170Convert R Data Structures to Python/Sage::
    167171
    168172    sage: rr = r.dnorm(r.seq(-3,3,0.1))
    169173    sage: sum(rr._sage_())
    170     9.9772125168981081
     174    9.97721251689810...
    171175
    172 Or you get a dictionary to be able to access all the information.
     176Or you get a dictionary to be able to access all the information::
    173177
    174178    sage: rs = r.summary(r.c(1,4,3,4,3,2,5,1))
    175179    sage: rs
     
    181185      sage: d['_Names']
    182186      ['Min.', '1st Qu.', 'Median', 'Mean', '3rd Qu.', 'Max.']
    183187      sage: d['_r_class']
    184       'table'
     188      ['summaryDefault', 'table']
    185189
    186190It is also possible to access the plotting capabilities of R
    187191through Sage.  For more information see the documentation of
     
    447451
    448452
    449453    def _quit_string(self):
    450         """
     454        r"""
    451455        Return the string that when typed into R causes the R
    452456        interpreter to exit.
    453457       
    454         EXAMPLES:
     458        EXAMPLES::
     459
    455460            sage: r._quit_string()
    456461            'quit(save="no")'
    457462        """
    458463        return 'quit(save="no")'
    459464   
    460465    def _read_in_file_command(self, filename):
    461         """
    462         Returns the R command (as a string) to read in a file named
     466        r"""
     467        Return the R command (as a string) to read in a file named
    463468        filename into the R interpreter.
    464469
    465         EXAMPLES:
     470        EXAMPLES::
     471
    466472            sage: r._read_in_file_command('file.txt')
    467             'source(file=file("file.txt",open="r"))'
     473            'file=file("file.txt",open="r")\nsource(file)'
    468474        """
    469         return 'source(file=file("%s",open="r"))'%filename
     475        return 'file=file("%s",open="r")\nsource(file)'%filename
    470476
    471477    def read(self, filename):
    472         """
    473         Reads filename into the R interpreter by calling R's source function on a
     478        r"""
     479        Read filename into the R interpreter by calling R's source function on a
    474480        read-only file connection.
    475481
    476         EXAMPLES:
     482        EXAMPLES::
     483
    477484            sage: filename = tmp_filename()
    478485            sage: f = open(filename, 'w')
    479486            sage: f.write('a <- 2+2\n')
     
    526533
    527534    def version(self):
    528535        """
    529         Returns the version of R currently running.
     536        Return the version of R currently running.
    530537
    531538        OUTPUT:
    532             tuple of ints; string
    533539
    534         EXAMPLES:
     540        tuple of ints; string
     541
     542        EXAMPLES::
     543
    535544            sage: r.version()
    536             ((2, 10, 1), 'R version 2.10.1 (2009-12-14)')
     545            ((2, 14, 0), 'R version 2.14.0 (2011-10-31)')
    537546        """
    538547        major_re = re.compile('^major\s*(\d.*?)$', re.M)
    539548        minor_re = re.compile('^minor\s*(\d.*?)$', re.M)
     
    16501659            sage: rs = r.summary(r.c(1,4,3,4,3,2,5,1))
    16511660            sage: d = rs._sage_()
    16521661            sage: list(sorted(d.items()))
    1653             [('DATA', [1, 1.75, 3, 2.875, 4, 5]),
    1654              ('_Names', ['Min.', '1st Qu.', 'Median', 'Mean', '3rd Qu.', 'Max.']),
    1655              ('_r_class', 'table')]
     1662            [('DATA', [1, 1.75, 3, 2.875, 4, 5]), 
     1663             ('_Names', ['Min.', '1st Qu.', 'Median', 'Mean', '3rd Qu.', 'Max.']), 
     1664             ('_r_class', ['summaryDefault', 'table'])]
    16561665        """
    16571666        self._check_valid()
    16581667        P = self.parent()
     
    16981707        exp = rel_re_param.sub(self._subs_dots, exp)
    16991708
    17001709        # Rename class since it is a Python keyword
    1701         exp = re.sub(' class = "', ' _r_class = "',exp)
     1710        exp = re.sub(' class = ', ' _r_class = ',exp)
    17021711
    17031712        # Change 'structure' to '_r_structure'
    17041713        # TODO: check that we are outside of quotes ""
     
    19451954
    19461955def r_version():
    19471956    """
    1948     EXAMPLES:
     1957    Return the R version.
     1958
     1959    EXAMPLES::
     1960
    19491961        sage: r.version()
    1950         ((2, 10, 1), 'R version 2.10.1 (2009-12-14)')
     1962        ((2, 14, 0), 'R version 2.14.0 (2011-10-31)')
    19511963    """
    19521964    return r.version()
    19531965