Commit 5765ff89 authored by Radford Neal's avatar Radford Neal

more in apply test, .save of output

parent 0b8fb47a
...@@ -28,6 +28,16 @@ print(apply(M,1,f1)) ...@@ -28,6 +28,16 @@ print(apply(M,1,f1))
print(apply(M,2,f1)) print(apply(M,2,f1))
print(apply(M,1,f2,101.23)) print(apply(M,1,f2,101.23))
print(apply(M,2,f2,101.23)) print(apply(M,2,f2,101.23))
A <- array (1:12, c(2,2,3))
print(A)
print(apply(A,1,f1))
print(apply(A,2,f1))
print(apply(A,3,f1))
print(apply(A,c(1,3),f1))
print(apply(A,1,f2,101.23))
print(apply(A,2,f2,101.23))
print(apply(A,3,f2,101.23))
print(apply(A,c(1,3),f2,101.23))
# Check that delayed warnings refer to [[1L]] and [[3L]]. (They don't # Check that delayed warnings refer to [[1L]] and [[3L]]. (They don't
# if later calls modifiy earlier calls.) The first set of warnings are # if later calls modifiy earlier calls.) The first set of warnings are
...@@ -42,7 +52,10 @@ for (w in c(1,0)) { ...@@ -42,7 +52,10 @@ for (w in c(1,0)) {
print(eapply(as.environment(list(a=-1,b=2,c=-1)),sqrt)) print(eapply(as.environment(list(a=-1,b=2,c=-1)),sqrt))
M <- matrix(-1,3,4) M <- matrix(-1,3,4)
print(apply(M,1,sqrt)) print(apply(M,1,sqrt))
A <- array(-1,c(2,2,2))
print(apply(A,2,sqrt))
} }
warnings()
# Test that indexed value is corectly retained when the applied function # Test that indexed value is corectly retained when the applied function
# returns a function that references it. # returns a function that references it.
...@@ -65,3 +78,7 @@ fns <- apply (matrix(11:13,3,1), 1, function(x) function () x) ...@@ -65,3 +78,7 @@ fns <- apply (matrix(11:13,3,1), 1, function(x) function () x)
print(fns) print(fns)
print(c(fns[[1]](),fns[[2]](),fns[[3]]())) print(c(fns[[1]](),fns[[2]](),fns[[3]]()))
fns <- apply (array(1:8,c(2,2,2)), 1, function(x) function () x)
print(fns)
print(fns[[1]]())
print(fns[[2]]())
-- lapply:
$a
[1] 4.23
$b
[1] 9.23
$c
[1] 17.23
$a
[1] 104.23
$b
[1] 109.23
$c
[1] 117.23
-- vapply:
a b c
4.23 9.23 17.23
a b c
104.23 109.23 117.23
-- eapply:
$c
[1] 17.23
$b
[1] 9.23
$a
[1] 4.23
$c
[1] 117.23
$b
[1] 109.23
$a
[1] 104.23
-- apply:
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
[1] 23.23 27.23 31.23
[1] 7.23 16.23 25.23 34.23
[1] 123.23 127.23 131.23
[1] 107.23 116.23 125.23 134.23
, , 1
[,1] [,2]
[1,] 1 3
[2,] 2 4
, , 2
[,1] [,2]
[1,] 5 7
[2,] 6 8
, , 3
[,1] [,2]
[1,] 9 11
[2,] 10 12
[1] 37.23 43.23
[1] 34.23 46.23
[1] 11.23 27.23 43.23
[,1] [,2] [,3]
[1,] 5.23 13.23 21.23
[2,] 7.23 15.23 23.23
[1] 137.23 143.23
[1] 134.23 146.23
[1] 111.23 127.23 143.23
[,1] [,2] [,3]
[1,] 105.23 113.23 121.23
[2,] 107.23 115.23 123.23
-- checking warnings:
Warning in FUN(c(-1, 2, -1)[[1L]], ...) : NaNs produced
Warning in FUN(c(-1, 2, -1)[[3L]], ...) : NaNs produced
[[1]]
[1] NaN
[[2]]
[1] 1.414214
[[3]]
[1] NaN
Warning in FUN(c(-1, 2, -1)[[1L]], ...) : NaNs produced
Warning in FUN(c(-1, 2, -1)[[3L]], ...) : NaNs produced
[1] NaN 1.414214 NaN
Warning in FUN(list(-1, 2, -1)[[1L]], ...) : NaNs produced
Warning in FUN(list(-1, 2, -1)[[3L]], ...) : NaNs produced
$c
[1] NaN
$b
[1] 1.414214
$a
[1] NaN
Warning in FUN(newX[, i], ...) : NaNs produced
Warning in FUN(newX[, i], ...) : NaNs produced
Warning in FUN(newX[, i], ...) : NaNs produced
[,1] [,2] [,3]
[1,] NaN NaN NaN
[2,] NaN NaN NaN
[3,] NaN NaN NaN
[4,] NaN NaN NaN
Warning in FUN(array(newX[, i], d.call, dn.call), ...) : NaNs produced
Warning in FUN(array(newX[, i], d.call, dn.call), ...) : NaNs produced
[,1] [,2]
[1,] NaN NaN
[2,] NaN NaN
[3,] NaN NaN
[4,] NaN NaN
[[1]]
[1] NaN
[[2]]
[1] 1.414214
[[3]]
[1] NaN
[1] NaN 1.414214 NaN
$c
[1] NaN
$b
[1] 1.414214
$a
[1] NaN
[,1] [,2] [,3]
[1,] NaN NaN NaN
[2,] NaN NaN NaN
[3,] NaN NaN NaN
[4,] NaN NaN NaN
[,1] [,2]
[1,] NaN NaN
[2,] NaN NaN
[3,] NaN NaN
[4,] NaN NaN
There were 11 warnings (use warnings() to see them)
Warning messages:
1: In FUN(c(-1, 2, -1)[[3L]], ...) : NaNs produced
2: In FUN(c(-1, 2, -1)[[3L]], ...) : NaNs produced
3: In FUN(c(-1, 2, -1)[[3L]], ...) : NaNs produced
4: In FUN(c(-1, 2, -1)[[3L]], ...) : NaNs produced
5: In FUN(list(-1, 2, -1)[[3L]], ...) : NaNs produced
6: In FUN(list(-1, 2, -1)[[3L]], ...) : NaNs produced
7: In FUN(newX[, i], ...) : NaNs produced
8: In FUN(newX[, i], ...) : NaNs produced
9: In FUN(newX[, i], ...) : NaNs produced
10: In FUN(array(newX[, i], d.call, dn.call), ...) : NaNs produced
11: In FUN(array(newX[, i], d.call, dn.call), ...) : NaNs produced
-- checking function environments:
[[1]]
function ()
x
<environment: 0x278cf28>
[[2]]
function ()
x
<environment: 0x278cdd8>
[[3]]
function ()
x
<environment: 0x278cc88>
[1] 13 13 13
[[1]]
function ()
x
<environment: 0x27927e8>
[[2]]
function ()
x
<environment: 0x2792660>
[[3]]
function ()
x
<environment: 0x27924d8>
[1] 13 13 13
$c
function ()
x
<environment: 0x2797698>
$b
function ()
x
<environment: 0x27984b0>
$a
function ()
x
<environment: 0x2798360>
[1] 11 11 11
[[1]]
function ()
x
<environment: 0x279ed78>
[[2]]
function ()
x
<environment: 0x279eb10>
[[3]]
function ()
x
<environment: 0x27a0008>
[1] 13 13 13
[[1]]
function ()
x
<environment: 0x27a80d0>
[[2]]
function ()
x
<environment: 0x27a8dd0>
[,1] [,2]
[1,] 2 6
[2,] 4 8
[,1] [,2]
[1,] 2 6
[2,] 4 8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment