Skip to content

Commit 4c2721c

Browse files
committed
Merge branch 'issue-#759'
2 parents 2fd942b + 42e4a3a commit 4c2721c

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

R/decostand.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@
143143
x <- .calc_rclr(x, na.rm = na.rm, ...)
144144
else x <- t(.calc_rclr(t(x), na.rm = na.rm, ...))
145145
attr <- attr(x, "parameters")
146-
attr$margin <- MARGIN
146+
if (!is.null(attr)) # no transformation parameters with imputed matrix
147+
attr$margin <- MARGIN
147148
})
148149
if (any(is.nan(x)))
149150
warning("result contains NaN, perhaps due to impossible mathematical
@@ -221,13 +222,10 @@
221222
# Impute NAs if impute=TRUE
222223
# Otherwise return the transformation with NAs
223224
if (impute && any(is.na(xx))) {
224-
225225
xx <- optspace(xx, ropt = ropt, niter = niter, tol = tol,
226226
verbose = verbose)$M
227227
}
228-
229228
xx
230-
231229
}
232230

233231
.calc_alr <-
@@ -299,7 +297,7 @@
299297
x * para$minpos},
300298
"clr" = exp(sweep(x, para$margin, para$means, "+")) -
301299
para$pseudocount,
302-
"rclr" = { x[x == 0] <- -Inf # x==0 was set: should be safe
300+
"rclr" = { x[is.na(x)] <- -Inf # no imputation: 0 |-> NA
303301
exp(sweep(x, para$margin, para$means, "+"))},
304302
"wisconsin" = { x <- sweep(x, 1, para$total, "*")
305303
sweep(x, 2, para$max, "*") },

tests/decostand-tests.Rout.save

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,6 @@ attr(,"scaled:center")
338338
[6] -0.0216677154 -0.0095070243 -0.0129853877 -0.0151765084 0.0739366224
339339
[11] 0.0813752690 0.0153170116 -0.0001358339 -0.0203385433 -0.0102092705
340340
[16] -0.0133788389 0.0543704488 -0.0876478093 0.0272043261 -0.0319186959
341-
attr(,"parameters")
342-
attr(,"parameters")$margin
343-
[1] 1
344-
345341
attr(,"decostand")
346342
[1] "rclr"
347343
> decostand(testdata, method = "clr", pseudocount = 1)
@@ -879,4 +875,4 @@ col50 FALSE
879875
>
880876
> proc.time()
881877
user system elapsed
882-
0.437 0.048 0.482
878+
0.438 0.048 0.485

0 commit comments

Comments
 (0)