Skip to content

Commit

Permalink
Merge branch 'dev' into dev2
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajic committed Nov 27, 2024
2 parents ce9cad4 + 36b6bb9 commit 5d46e82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## enhancements

- `spatUnit()<-` and `featType()<-` `list` methods
- `set_default_spat_unit()` and `set_default_feat_type()` now look for defaults when given `NA_character_` inputs as well.

# GiottoClass 0.4.4 (2024/11/14)

Expand Down
12 changes: 8 additions & 4 deletions R/defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ set_default_spat_unit <- function(
gobject,
spat_unit = NULL) {
# If a spatial unit is provided, use it directly
if (!is.null(spat_unit)) {
null_input <- is.null(spat_unit)
na_input <- isTRUE(is.na(spat_unit[[1]]))
if (!null_input && !na_input) {
if (!inherits(spat_unit, "character")) {
stop("spat_unit input must be character")
}
Expand All @@ -29,7 +31,7 @@ set_default_spat_unit <- function(
spat_unit <- try(instructions(gobject, "active_spat_unit"), silent = TRUE)

if (inherits(spat_unit, "try-error")) {
if (!is.null(gobject@expression) & length(gobject@expression) > 0L) {
if (!is.null(gobject@expression) && length(gobject@expression) > 0L) {
spat_unit <- names(gobject@expression)[[1L]]
} else if (!is.null(gobject@spatial_info)) {
spat_unit <- names(gobject@spatial_info)[[1L]]
Expand Down Expand Up @@ -62,7 +64,9 @@ set_default_feat_type <- function(
feat_type = NULL,
spat_unit) {
# if a feature type is provided, use it directly
if (!is.null(feat_type)) {
null_input <- is.null(feat_type)
na_input <- isTRUE(is.na(feat_type[[1]]))
if (!null_input && !na_input) {
if (!inherits(feat_type, "character")) {
stop("feat_type input must be character")
}
Expand All @@ -73,7 +77,7 @@ set_default_feat_type <- function(
feat_type <- try(instructions(gobject, "active_feat_type"), silent = TRUE)

if (inherits(feat_type, "try-error")) {
if (!is.null(gobject@expression) & length(gobject@expression) > 0L) {
if (!is.null(gobject@expression) && length(gobject@expression) > 0L) {
feat_type <- names(gobject@expression[[spat_unit]])[[1L]]
if (is.null(feat_type)) {
warning(wrap_txt("No existing feat_types to default to in given
Expand Down

0 comments on commit 5d46e82

Please sign in to comment.