knitr error in sort.int - unable to knit a chunk with boxplot codes
1
0
Entering edit mode
@poojithastemcell-11859
Last seen 3.7 years ago
United Kingdom

I have a code chunk which gets stuck while knitting and gives the following error:

boxplot(rawdata_order, frame.plot=F, cex.axis=0.7, main="Raw data",border=NULL)
boxplot(affy_normalised_data, frame.plot=F,cex.axis=0.7, main="Normalized data",border=NULL)
hist(rawdata_order, cex.axis=0.7, frame.plot=F, main="Raw data")
hist(affy_normalised_data, cex.axis=0.7, frame.plot=F, main="Normalized data")

***Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 
  'x' must be atomic
Calls: <Anonymous> ... boxplot.stats -> <Anonymous> -> sort -> sort.default -> sort.int***

The code chunk runs fine on its own. However, when I knit the document, I am unable to get past the first line of this code chunk. Can anyone help me resolve this issue?

knitr boxplot • 1.0k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 1 day ago
United States

You may need to specify the function using the :: operator, to ensure you are using the one you intend. I presume you are using boxplot and hist from the affy package, so that would be affy::boxplot, etc. If I force the usage of the graphics boxplot, I get the same error you see:

> data(Dilution)
> graphics::boxplot(Dilution)
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 
  'x' must be atomic

An alternative is that you aren't loading the affy package in your RMD (or Rnw if you are kicking things old school), in which case you have to load the package to get the function.

ADD COMMENT
0
Entering edit mode

It makes sense. I tried this, but I still end up with the same error. Am I missing something?

library(affy)
affy::boxplot(rawdata_order, frame.plot=F, cex.axis=0.7, main="Raw data",border=NULL)
affy::boxplot(affy_normalised_data, frame.plot=F,cex.axis=0.7, main="Normalized data",border=NULL)
affy::hist(rawdata_order, cex.axis=0.7, frame.plot=F, main="Raw data")
affy::hist(affy_normalised_data, cex.axis=0.7, frame.plot=F, main="Normalized data")
***Quitting from lines 141-146 (affy-script.Rmd) 
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 
  'x' must be atomic
Calls: <Anonymous> ... boxplot.stats -> <Anonymous> -> sort -> sort.default -> sort.int
Execution halted***
ADD REPLY
0
Entering edit mode

What are affy_normalized_data and rawdata_order? They appear not to be ExpressionSets.

class(affy_normalized_data)
class(rawdata_order)
ADD REPLY
0
Entering edit mode

They are expression sets.

class(affy_normalised_data)
[1] "ExpressionSet"
attr(,"package")
[1] "Biobase"
class(rawdata_order)
[1] "AffyBatch"
attr(,"package")
[1] "affy"

The codes for boxplot and hist runs fine on their own. Its only when I knit the file that it gets stuck at that line.

ADD REPLY
0
Entering edit mode

Ugh. My bad. I meant AffyBatch. There might be a boxplot method that dispatches on ExpressionSet objects, but it's not in Biobase, nor affy. You could load whatever you have loaded when it works interactively and then do

selectMethod("boxplot", "ExpressionSet")

To see where it's coming from. As an example, for AffyBatch objects we get

> selectMethod("boxplot", "AffyBatch")
Method Definition:

function (x, ...) 
{
    .local <- function (x, which = "both", range = 0, main, ...) 
    {
        tmp <- description(x)
        if (missing(main) && (is(tmp, "MIAME"))) 
            main <- tmp@title
        tmp <- unlist(indexProbes(x, which))
        tmp <- tmp[seq(1, length(tmp), len = 5000)]
        boxplot(data.frame(log2(intensity(x)[tmp, ])), main = main, 
            range = range, ...)
    }
    .local(x, ...)
}
<bytecode: 0x5b122a8>
<environment: namespace:affy>

Signatures:
        x          
target  "AffyBatch"
defined "AffyBatch"

And you can see there is a defined method in affy to do this. But

> selectMethod("boxplot", "ExpressionSet")
Method Definition (Class "derivedDefaultMethod"):

function (x, ...) 
UseMethod("boxplot")
<bytecode: 0x32bc560>
<environment: namespace:graphics>

Signatures:
        x              
target  "ExpressionSet"
defined "ANY"          

For ExpressionSet objects it's just dispatching to the S3 method in graphics, which doesn't know how to handle it.

Alternatively (and maybe easier?) would be to do things by hand, by extracting the exprs slot directly:

boxplot(exprs(affy_normalized_data))
ADD REPLY

Login before adding your answer.

Traffic: 528 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6