Skip to content

Commit c0409b2

Browse files
author
alikhuseynov
committed
replaced is with inherits
1 parent 4e6d24e commit c0409b2

10 files changed

+21
-21
lines changed

R/SFEMethod-bivariate.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' @importFrom DelayedArray sweep
1313
.lee_mat <- function(x, y = NULL, listw, zero.policy = TRUE, ...) {
1414
# X has genes in rows
15-
if (is(listw, "listw"))
15+
if (inherits(listw, "listw"))
1616
W <- listw2sparse(listw)
1717
else W <- listw
1818
x <- .scale_n(x)

R/SFEMethod-multivariate.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ multispati_rsp <- function(x, listw, nfposi = 30L, nfnega = 30L, scale = TRUE) {
5252
stop("At least one of nfposi and nfnega must be positive.")
5353
}
5454
x <- sweep(x, 2, colMeans(x))
55-
if (is(x, "dgeMatrix")) x <- as.matrix(x)
55+
if (inherits(x, "dgeMatrix")) x <- as.matrix(x)
5656
if (scale) {
5757
# Note that dudi.pca divides by n instead of n-1 when scaling data
5858
n <- nrow(x)
5959
x <- sweep(x, 2, sqrt(matrixStats::colVars(x)*(n-1)/n), FUN = "/")
6060
}
6161
if (inherits(listw, "Matrix") || is.matrix(listw))
6262
W <- listw
63-
else if (is(listw, "listw"))
63+
else if (inherits(listw, "listw"))
6464
W <- listw2sparse(listw)
6565
else
6666
stop("listw must be either a listw object or an adjacency matrix.")

R/bivariate.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ setMethod("calculateBivariate", "ANY",
148148
out <- reorganize_fun(type)(out, name = name, ...)
149149
}
150150
}
151-
if (length(out) == 1L && !is(out, "DataFrame")) out <- out[[1]]
151+
if (length(out) == 1L && !inherits(out, "DataFrame")) out <- out[[1]]
152152
out
153153
})
154154

R/multivariate.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ setMethod("calculateMultivariate", "SpatialFeatureExperiment",
178178

179179
is_vector <- all(vapply(out, is.vector, FUN.VALUE = logical(1)))
180180
is_matrix <- all(vapply(out, is.matrix, FUN.VALUE = logical(1)))
181-
is_df <- all(vapply(out, function(o) is.data.frame(o) | is(o, "DataFrame"),
181+
is_df <- all(vapply(out, function(o) is.data.frame(o) | inherits(o, "DataFrame"),
182182
FUN.VALUE = logical(1)))
183183
if (is_vector) {
184184
out <- unlist(out)
@@ -223,7 +223,7 @@ runMultivariate <- function(x, type, colGraphName = 1L,
223223
reducedDim(x, name) <- out
224224
} else {
225225
if (is.vector(out)) colData(x)[[name]] <- out
226-
if (is.data.frame(out) || is(out, "DataFrame")) {
226+
if (is.data.frame(out) || inherits(out, "DataFrame")) {
227227
inds <- !grepl(name, names(out))
228228
names(out)[inds] <- paste(name, names(out)[inds], sep = "_")
229229
colData(x) <- cbind(colData(x), out)

R/plot-univar-downstream.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
warning("Too few points for stat_density2d, not plotting contours.")
3939
}
4040
)
41-
if (is(p_test, "ggplot_built")) {
41+
if (inherits(p_test, "ggplot_built")) {
4242
p <- p + geom_density2d(color = contour_color, bins = bins, ...)
4343
}
4444
p <- p +

R/plot.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ getDivergeRange <- function(values, diverge_center = 0) {
412412

413413
#' @importFrom sf st_as_sfc st_bbox st_intersection
414414
.bbox_sample <- function(df, bbox) {
415-
if (is(df, "sf")) {
415+
if (inherits(df, "sf")) {
416416
# Only for one sample
417417
bbox_use <- st_as_sfc(st_bbox(bbox))
418418
suppressWarnings(df <- st_intersection(df, bbox_use))
@@ -659,7 +659,7 @@ getDivergeRange <- function(values, diverge_center = 0) {
659659
# the bbox is a large part of the image that also needs to be written to
660660
# disk
661661
imgs <- lapply(imgs, function(x) {
662-
if (is(x, "SpatRasterImage")) {
662+
if (inherits(x, "SpatRasterImage")) {
663663
tot_area <- ext(x) |> st_bbox() |> st_as_sfc() |> st_area()
664664
bb_area <- bbox |> st_bbox() |> st_as_sfc() |> st_area()
665665
bb_prop <- bb_area/tot_area
@@ -684,10 +684,10 @@ getDivergeRange <- function(values, diverge_center = 0) {
684684
}
685685
# All convert to SpatRaster
686686
imgs <- lapply(imgs, function(img) {
687-
if (is(img, "BioFormatsImage")) {
687+
if (inherits(img, "BioFormatsImage")) {
688688
res_use <- .find_res(img, maxcell)
689689
spi <- toSpatRasterImage(img, resolution = res_use, save_geotiff = FALSE)
690-
} else if (is(img, "ExtImage")) {
690+
} else if (inherits(img, "ExtImage")) {
691691
spi <- toSpatRasterImage(img, save_geotiff = FALSE)
692692
} else spi <- img
693693
spi |> resample_spat(maxcell)
@@ -772,7 +772,7 @@ getDivergeRange <- function(values, diverge_center = 0) {
772772
img_df <- .get_img_df(sfe, sample_id, image_id, channel, bbox, maxcell,
773773
normalize_channels)
774774
} else img_df <- NULL
775-
if (is(img_df, "DataFrame") && !nrow(img_df)) img_df <- NULL
775+
if (inherits(img_df, "DataFrame") && !nrow(img_df)) img_df <- NULL
776776
.wrap_spatial_plots(
777777
df, annot_df, img_df, channel, type_annot, values, aes_use,
778778
annot_aes, annot_fixed, tx_fixed, size, shape, linewidth, linetype, alpha,

R/plotLocalResult.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ plotLocalResult <- function(sfe, name, features, attribute = NULL,
206206
channel, bbox, maxcell,
207207
normalize_channels)
208208
else img_df <- NULL
209-
if (is(img_df, "DataFrame") && !nrow(img_df)) img_df <- NULL
209+
if (inherits(img_df, "DataFrame") && !nrow(img_df)) img_df <- NULL
210210
if (!is.null(rowGeometryName)) {
211211
tx_df <- .get_tx_df(sfe, data_dir = NULL, tech = NULL, file = NULL,
212212
sample_id = sample_id, spatialCoordsNames = c("X", "Y"),
@@ -229,7 +229,7 @@ plotLocalResult <- function(sfe, name, features, attribute = NULL,
229229
)
230230
}
231231
# Add title to not to confuse with gene expression
232-
if (is(out, "patchwork")) {
232+
if (inherits(out, "patchwork")) {
233233
out <- out + plot_annotation(title = title_use)
234234
} else {
235235
out <- out + ggtitle(title_use)

R/plotSpatialReducedDim.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ spatialReducedDim <- function(sfe, dimred, ncomponents = NULL,
7575
normalize_channels = normalize_channels, rowGeometryName = rowGeometryName,
7676
rowGeometryFeatures = rowGeometryFeatures, tx_file = tx_file, ...
7777
)
78-
if (is(out, "patchwork")) {
78+
if (inherits(out, "patchwork")) {
7979
out <- out + plot_annotation(title = dimred)
8080
} else {
8181
out <- out + ggtitle(dimred)

R/univariate-internal.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Internal function for univariate metrics
22
.calc_univar <- function(x, fun, BPPARAM, ...) {
3-
if (is(x, "DFrame") || is.data.frame(x)) {
4-
if (is(x, "sf")) x <- st_drop_geometry(x)
3+
if (inherits(x, "DFrame") || is.data.frame(x)) {
4+
if (inherits(x, "sf")) x <- st_drop_geometry(x)
55
x <- t(as.matrix(x))
66
if (anyNA(x)) {
77
stop("Only numeric columns without NA (within the sample_id) can be used.")
@@ -17,12 +17,12 @@
1717
#' @importFrom stats as.formula terms
1818
.get_coords_df <- function(x, df, sample_id, exprs_values,
1919
swap_rownames, ...) {
20-
if (!is(df, "sf") || st_geometry_type(df, by_geometry = FALSE) != "POINT") {
21-
if (is(df, "sf")) df <- st_drop_geometry(df)
20+
if (!inherits(df, "sf") || st_geometry_type(df, by_geometry = FALSE) != "POINT") {
21+
if (inherits(df, "sf")) df <- st_drop_geometry(df)
2222
# Can't use list columns as regressors
2323
inds_keep <- vapply(df, is.atomic, FUN.VALUE = logical(1))
2424
df <- df[,inds_keep]
25-
if (is(df, "DataFrame")) df <- as.data.frame(df)
25+
if (inherits(df, "DataFrame")) df <- as.data.frame(df)
2626
colnames_use <- spatialCoordsNames(x)
2727
geo <- df2sf(spatialCoords(x)[x$sample_id == sample_id,], colnames_use)
2828
oth_names <- setdiff(names(df), colnames_use)

R/utils.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
}
196196

197197
.get_not_na_items <- function(df, features, colname_use) {
198-
if (is(df, "sf")) df <- st_drop_geometry(df)
198+
if (inherits(df, "sf")) df <- st_drop_geometry(df)
199199
if (!colname_use %in% names(df)) {
200200
return(NULL)
201201
}

0 commit comments

Comments
 (0)