Nanostring-Biostats / SpatialOmicsOverlay

Tools for analyzing data on the image from NanoString GeoMx Digital Spatial Profiler (DSP).
MIT License
17 stars 4 forks source link

Error in if (nchar(x) > bookend * 2) { : the condition has length > 1 #47

Closed EsperanzaDai closed 11 months ago

EsperanzaDai commented 1 year ago

Found a bug in the bookendStr function. Original function:

bookendStr <<- function(x, bookend = 8){
    if(!is(x,"character")){
        x <- as.character(x)
    }
    if(nchar(x) > bookend*2){
        x <- paste(substr(x = x, start = 1, stop = bookend), "...",
                   substr(x = x, start = nchar(x)-(bookend-1), stop = nchar(x)),
                   paste0("(", nchar(x), " total char)"))
    }
    return(x)
}

Suggesting adding one thing: the [1] after nchar(x) in the second if.

bookendStr <<- function(x, bookend = 8){
    if(!is(x,"character")){
        x <- as.character(x)
    }
    if(nchar(x)[1] > bookend*2){
        x <- paste(substr(x = x, start = 1, stop = bookend), "...",
                   substr(x = x, start = nchar(x)-(bookend-1), stop = nchar(x)),
                   paste0("(", nchar(x), " total char)"))
    }
    return(x)
}

Otherwise, if x is a vector with more than one character giving the error in the title. E.g. SpatialPosition calls this function and has a glitch in printing the results for position column.

maddygriz commented 1 year ago

Hi @EsperanzaDai,

Thanks for suggesting a fix for this. The call in SpatialPosition is expecting a single value and not a vector so I'm curious if something else is happening with your data. Do you have multiple columns named "Position" when you call colnames(SpatialOverlay@overlayData@position)? Or what is length(position(SpatialOverlay@overlayData@position))?

Maddy

EsperanzaDai commented 1 year ago

colnames(SOobject@overlayData@position) [1] "ROILabel" "Sample_ID" "Height" "Width" "X" [6] "Y" "Segmentation" "Position"

I got this error when trying to call SpatialPosition(AttributeTable). I think within this function class, all values from the position column are input for the bookendStr function. If there are multiple ROIs, then nchar(x)[1] will work instead of nchar(x).

Thank you!

maddygriz commented 11 months ago

Hi @EsperanzaDai,

Sorry for the long delay but there will be a fix for this in the next Bioconductor release. Thanks for bringing it to our attention.

Maddy