package ocaml-r

  1. Overview
  2. Docs

Source file OCamlR_grDevices.ml

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
open OCamlR

let () = ignore (eval_string "require(grDevices, quietly=TRUE)")

module Stub = struct

  let png = symbol "png"

  let pdf = symbol "pdf"

  let postscript = symbol "postscript"

  let svg = symbol "svg"

  let dev_off = symbol "dev.off"

  (* TODO: This segfaults: let dev = symbol "dev" *)

end

type length_unit = [`pixel | `inch | `cm | `mm]

let string_of_length_unit = function
  | `pixel -> "px"
  | `inch -> "in"
  | `cm -> "cm"
  | `mm -> "mm"

let r_length_unit x = Enc.string (string_of_length_unit x)

let png ?width ?height ?unit ?pointsize path =
  ignore (
    call Stub.png [
      arg Enc.string                  path ;
      opt_arg Enc.float       "width"     width ;
      opt_arg Enc.float       "height"    height ;
      opt_arg r_length_unit "unit"      unit ;
      opt_arg Enc.int         "pointsize" pointsize
    ])

let pdf ?width ?height ?pointsize path =
  ignore (
    call Stub.pdf [
      arg Enc.string                  path ;
      opt_arg Enc.float       "width"     width ;
      opt_arg Enc.float       "height"    height ;
      opt_arg Enc.int         "pointsize" pointsize
    ])

let postscript ?width ?height ?pointsize path =
  ignore (
    call Stub.postscript [
      arg Enc.string                  path ;
      opt_arg Enc.float       "width"     width ;
      opt_arg Enc.float       "height"    height ;
      opt_arg Enc.int         "pointsize" pointsize
    ])

let svg ?width ?height ?pointsize path =
  ignore (
    call Stub.svg [
      arg Enc.string                  path ;
      opt_arg Enc.float       "width"     width ;
      opt_arg Enc.float       "height"    height ;
      opt_arg Enc.int         "pointsize" pointsize
    ])

let dev_off () =
  ignore (
    call Stub.dev_off []
  )
OCaml

Innovation. Community. Security.