You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-5Lines changed: 42 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,23 @@ expressions use usual loops (`for`, `while` and `repeat`) and usual `if` as
10
10
list producers. Syntax is very similar to Python. The difference is that
11
11
returned value should be at the end of the loop body.
12
12
13
-
```R
14
-
# rather useless statement - squares of even numbers
15
-
to_list(for(iin1:10) if(i%%2==0) i*i)
13
+
There are three main functions:
16
14
17
-
# Pythagorean triples
18
-
to_list(for (xin1:20) for (yinx:20) for (ziny:20) if (x^2+y^2==z^2) c(x, y, z))
15
+
-`to_list` converts usual R loops expressions to list producers. Expression should be started with `for`, `while` or `repeat`. You can iterate over multiple lists if you provide several loop variables in backticks. See examples.
16
+
-`to_vec` is the same as `to_list` but return vector. See examples.
17
+
-`alter` return the same type as its argument but with modified elements. It is useful for altering existing data.frames or lists. See examples.
19
18
19
+
Rather unpractical example - squares of even numbers:
20
+
```R
21
+
library(comprehenr)
22
+
to_vec(for(iin1:10) if(i%%2==0) i*i)
23
+
```
24
+
Pythagorean triples:
25
+
```R
26
+
to_list(for (xin1:20) for (yinx:20) for (ziny:20) if (x^2+y^2==z^2) c(x, y, z))
0 commit comments