The 'list' object cannot be coerced to type 'double' in R shiny

1.1K    Asked by GuyRodd in Data Science , Asked on Apr 19, 2021

When I run the following code in R then I am not getting any error, but if I run the same code in R shiny, then I am getting the following error:

error 'list' "object cannot be coerced to type 'double' "

In the code, the f2 is the file that is being uploaded by the user, and that file contains only 1 column and multiple rows with 1 word each.

s = vector("list", 1)

#the loop below runs over the length of no of genes all written in different rows

for (i in 1:length(f2[,1])) { s[i] = list({ y = lapply(1:6, function(x) apc[[x]]$Logâ‚‚ fold change[apc[[x]]$Name== f2[i,1]] ) unlist(as.numeric(y))
}) }

Answered by Guy Rodd

While observing your error, I think the message might have something to do with the statement unlist(as.numeric(y)):

You can simply try the following code, but this will also throw an error message:

    as.numeric(list(c("1", "2"), "3")) # error: 'list' object cannot be coerced to type 'double'

But if you run:

    as.numeric(list("1", "2"))

This will work.

In last what you can do is save it by switching the commands. First, try to unlist, then type-cast second:

    as.numeric(unlist(list(c("1", "2"), "3"))) # works: c(1, 2, 3)

Note: This error frequently shows up when you've got a list of numeric strings which you want R to treat as numbers.



Your Answer

Interviews

Parent Categories