Displaying 4 results from an estimated 4 matches for "sexsnp".
Did you mean:
sexp
2023 May 18
1
suprising behaviour of tryCatch()
G'day Federico,
On Wed, 17 May 2023 10:42:17 +0000
"Calboli Federico (LUKE)" <federico.calboli at luke.fi> wrote:
> sexsnp = rep(NA, 1750)
> for(i in 1:1750){tryCatch(sexsnp[i] = fisher.test(table(data[,3],
> data[,i + 38]))$p, error = function(e) print(NA))} Error: unexpected
> '=' in "for(i in 1:1750){tryCatch(sexsnp[i] ="
Try:
R> for(i in 1:1750){tryCatch(eval(expression("sexsnp[...
2023 May 17
4
suprising behaviour of tryCatch()
Hello,
I run a fisher.test() in a loop, with the issue that some of the data will not be useable. To protect the loop I used tryCatch but:
sexsnp = rep(NA, 1750)
for(i in 1:1750){tryCatch(sexsnp[i] = fisher.test(table(data[,3], data[,i + 38]))$p, error = function(e) print(NA))}
Error: unexpected '=' in "for(i in 1:1750){tryCatch(sexsnp[i] ="
But this works:
for(i in 1:1750){tryCatch(sexsnp[i] <- fisher.test(table(data[...
2023 May 18
1
suprising behaviour of tryCatch()
...ill put the bottle on the top
shelf inside of the refrigerator
refrigerator( topshelf <- bottle ) will put the bottle on the top
shelf in the same room that the refrigerator is in (but not in the
fridge itself)
When you run the code with `<-` it, then the ith element of the global
variable `sexsnp` is assigned the p-value. When you run the version
with `=` then R tries to find an argument to `tryCatch` that matches
(possibly partially) `sexsnp[i]` and gives the error because it does
not find a match (not sure why it is not handled by `...`, but
tryCatch may be parsed special, or non-legal a...
2023 May 18
1
suprising behaviour of tryCatch()
... or just put the R expression inside curly brackets, e.g.
tryCatch({
sexsnp[i] = fisher.test(table(data[,3], data[,i+38]))$p
}, error=function(e) print(NA))
Exercise: Compare
> list(a = 2)
$a
[1] 2
with
> list({ a = 2 })
[[1]]
[1] 2
and
> list(b = { a = 2 })
$b
[1] 2
BTW, note how the latter two assigned a <- 2 to the global environment.
/Henrik
On Thu...