File: python-dict.R

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 (39 lines) | stat: -rw-r--r-- 788 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
#' @export
`$.python.builtin.dict` <- function(x, name) {
  attr <- py_get_attr(x, name, TRUE)
  if(is.null(attr))
    py_dict_get_item(x, name)
  else
    py_maybe_convert(attr, py_has_convert(x))
}

#' @export
`[.python.builtin.dict` <- function(x, name) {
  py_dict_get_item(x, name)
}

#' @export
`[[.python.builtin.dict` <- `[.python.builtin.dict`

#' @export
`$<-.python.builtin.dict` <- function(x, key, value) {
  if(is.null(value))
    py_del_item(x, key)
  else
    py_dict_set_item(x, key, value)
  x
}

#' @export
`[<-.python.builtin.dict` <- `$<-.python.builtin.dict`

#' @export
`[[<-.python.builtin.dict` <- `$<-.python.builtin.dict`

#' @export
length.python.builtin.dict <- function(x) {
  if (py_is_null_xptr(x) || !py_available())
    0L
  else
    py_dict_length(x)
}