File: test-optional_arguments.2.R

package info (click to toggle)
r-cran-lambda.r 1.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 284 kB
  • sloc: sh: 9; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 753 bytes parent folder | download | duplicates (2)
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
# vim: set filetype=R
rm(list=ls())
assert('optional_arguments_no_args', {
  f(name='ROOT') %as% 1
  seal(f)
  (f() == 1)
  (f('a') == 1)
})

rm(list=ls())
assert('optional_arguments_no_args_type_constraint', {
  f(name) %::% character : numeric
  f(name='ROOT') %as% 1
  seal(f)
  (f() == 1)
  (f('a') == 1)
})

rm(list=ls())
assert('optional_arguments_function', {
  f(x, y=runif(5)) %as% { x + y }
  seal(f)
  act <- f(1)
  (length(act) == 5)
})

rm(list=ls())
assert('optional_arguments_function_named', {
  f(y=runif(5), x) %as% { x + y }
  seal(f)
  act <- f(x=1)
  (length(act) == 5)
})

rm(list=ls())
assert('optional_arguments_reference_var', {
  f(y=min(x), x) %as% { x + y }
  seal(f)
  act <- f(x=1:5)
  (length(act) == 5)
  (act == 2:6)
})