File: Ops-python-methods.Rd

package info (click to toggle)
r-cran-reticulate 1.41.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,088 kB
  • sloc: cpp: 5,154; python: 620; sh: 13; makefile: 2
file content (104 lines) | stat: -rw-r--r-- 4,070 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/python.R
\name{==.python.builtin.object}
\alias{==.python.builtin.object}
\alias{!=.python.builtin.object}
\alias{<.python.builtin.object}
\alias{>.python.builtin.object}
\alias{>=.python.builtin.object}
\alias{<=.python.builtin.object}
\alias{+.python.builtin.object}
\alias{-.python.builtin.object}
\alias{*.python.builtin.object}
\alias{/.python.builtin.object}
\alias{\%/\%.python.builtin.object}
\alias{\%\%.python.builtin.object}
\alias{^.python.builtin.object}
\alias{&.python.builtin.object}
\alias{|.python.builtin.object}
\alias{!.python.builtin.object}
\alias{\%*\%.python.builtin.object}
\title{S3 Ops Methods for Python Objects}
\usage{
\method{==}{python.builtin.object}(e1, e2)

\method{!=}{python.builtin.object}(e1, e2)

\method{<}{python.builtin.object}(e1, e2)

\method{>}{python.builtin.object}(e1, e2)

\method{>=}{python.builtin.object}(e1, e2)

\method{<=}{python.builtin.object}(e1, e2)

\method{+}{python.builtin.object}(e1, e2)

\method{-}{python.builtin.object}(e1, e2)

\method{*}{python.builtin.object}(e1, e2)

\method{/}{python.builtin.object}(e1, e2)

\method{\%/\%}{python.builtin.object}(e1, e2)

\method{\%\%}{python.builtin.object}(e1, e2)

\method{^}{python.builtin.object}(e1, e2)

\method{&}{python.builtin.object}(e1, e2)

\method{|}{python.builtin.object}(e1, e2)

\method{!}{python.builtin.object}(e1)

\method{\%*\%}{python.builtin.object}(x, y)
}
\arguments{
\item{e1, e2, x, y}{A python object.}
}
\value{
Result from evaluating the Python expression. If either of the
arguments to the operator was a Python object with \code{convert=FALSE}, then
the result will also be a Python object with \code{convert=FALSE} set.
Otherwise, the result will be converted to an R object if possible.
}
\description{
Reticulate provides S3 Ops Group Generic Methods for Python objects. The methods
invoke the equivalent python method of the object.
}
\section{Operator Mappings}{
\tabular{lll}{
   R expression \tab Python expression \tab First python method invoked \cr
   \code{x == y} \tab \code{x == y} \tab \verb{type(x).__eq__(x, y)} \cr
   \code{x != y} \tab \code{x != y} \tab \verb{type(x).__ne__(x, y)} \cr
   \code{x < y} \tab \code{x < y} \tab \verb{type(x).__lt__(x, y)} \cr
   \code{x > y} \tab \code{x > y} \tab \verb{type(x).__gt__(x, y)} \cr
   \code{x >= y} \tab \code{x >= y} \tab \verb{type(x).__ge__(x, y)} \cr
   \code{x <= y} \tab \code{x <= y} \tab \verb{type(x).__le__(x, y)} \cr
   \code{+ x } \tab \code{+ x} \tab \verb{type(x).__pos__(x)} \cr
   \code{- y} \tab \code{- x} \tab \verb{type(x).__neg__(x)} \cr
   \code{x + y} \tab \code{x + y} \tab \verb{type(x).__add__(x, y)} \cr
   \code{x - y} \tab \code{x - y} \tab \verb{type(x).__sub__(x, y)} \cr
   \code{x * y} \tab \code{x * y} \tab \verb{type(x).__mul__(x, y)} \cr
   \code{x / y} \tab \code{x / y} \tab \verb{type(x).__truediv__(x, y)} \cr
   \code{x \%/\% y} \tab \verb{x // y} \tab \verb{type(x).__floordiv__(x, y)} \cr
   \code{x \%\% y} \tab \verb{x \% y} \tab \verb{type(x).__mod__(x, y)} \cr
   \code{x ^ y} \tab \code{x ** y} \tab \verb{type(x).__pow__(x, y)} \cr
   \code{x & y} \tab \code{x & y} \tab \verb{type(x).__and__(x, y)} \cr
   \code{x | y} \tab \code{x | y} \tab \verb{type(x).__or__(x, y)} \cr
   \code{!x} \tab \code{~x} \tab \verb{type(x).__not__(x)} \cr
   \code{x \%*\% y} \tab \code{x @ y} \tab \verb{type(x).__matmul__(x, y)} \cr
}


Note: If the initial Python method invoked raises a \code{NotImplemented}
Exception, the Python interpreter will attempt to use the reflected
variant of the method from the second argument. The arithmetic operators
will call the equivalent double underscore (dunder) method with an "r" prefix. For
instance, when evaluating the expression \code{x + y}, if \verb{type(x).__add__(x, y)}
raises a \code{NotImplemented} exception, then the interpreter will attempt
\verb{type(y).__radd__(y, x)}. The comparison operators follow a different
sequence of fallbacks; refer to the Python documentation for more details.
}