Skip to content

Commit 5bf2268

Browse files
authored
Merge pull request #171 from bhklab/feat/view-updateobject-guidance
feat: add guarded View shim for CoreSet/PharmacoSet
2 parents cc40854 + bedac78 commit 5bf2268

5 files changed

Lines changed: 108 additions & 1 deletion

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ local_data/**
2424
.VSCodeCounter/**
2525
*.o
2626
docs
27+
28+
# build artifacts
29+
*.tar.gz
30+
*.Rcheck/
31+
*.BiocCheck/

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Imports:
5858
Depends: R (>= 3.6), CoreGx
5959
LinkingTo: Rcpp
6060
Roxygen: list(markdown = TRUE, r6=FALSE)
61-
RoxygenNote: 7.3.1
61+
RoxygenNote: 7.3.2
6262
VignetteBuilder: knitr
6363
VignetteEngine: knitr::rmarkdown
6464
biocViews: GeneExpression, Pharmacogenetics, Pharmacogenomics, Software, Classification
@@ -102,6 +102,7 @@ Collate:
102102
'logLogisticRegression.R'
103103
'matthewCor.R'
104104
'mergePSets.R'
105+
'methods-View.R'
105106
'methods-[.R'
106107
'methods-drugSensitivitySig.R'
107108
'methods-intersect.R'

NAMESPACE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export(.plotProjHill)
1212
export(PharmacoSet)
1313
export(PharmacoSet2)
1414
export(PharmacoSig)
15+
export(View)
1516
export(amcc)
1617
export(availablePSets)
1718
export(checkPsetStructure)
@@ -111,6 +112,8 @@ importClassesFrom(CoreGx,CoreSet)
111112
importClassesFrom(CoreGx,LongTable)
112113
importClassesFrom(CoreGx,TreatmentResponseExperiment)
113114
importClassesFrom(MultiAssayExperiment,MultiAssayExperiment)
115+
importClassesFrom(S4Vectors,DataFrame)
116+
importClassesFrom(S4Vectors,List)
114117
importFrom(Biobase,AnnotatedDataFrame)
115118
importFrom(BiocParallel,bplapply)
116119
importFrom(CoreGx,"sampleInfo<-")
@@ -143,6 +146,7 @@ importFrom(CoreGx,sampleNames)
143146
importFrom(CoreGx,subsetByFeature)
144147
importFrom(CoreGx,treatmentNames)
145148
importFrom(CoreGx,updateSampleId)
149+
importFrom(MultiAssayExperiment,MultiAssayExperiment)
146150
importFrom(S4Vectors,DataFrame)
147151
importFrom(S4Vectors,SimpleList)
148152
importFrom(S4Vectors,metadata)
@@ -159,11 +163,22 @@ importFrom(SummarizedExperiment,colData)
159163
importFrom(SummarizedExperiment,rowData)
160164
importFrom(boot,boot)
161165
importFrom(boot,boot.ci)
166+
importFrom(checkmate,assert)
167+
importFrom(checkmate,assertCharacter)
168+
importFrom(checkmate,assertClass)
169+
importFrom(checkmate,assertDataFrame)
162170
importFrom(checkmate,assertDataTable)
163171
importFrom(checkmate,assertInt)
172+
importFrom(checkmate,assertList)
164173
importFrom(checkmate,assertLogical)
165174
importFrom(checkmate,assertNumeric)
175+
importFrom(checkmate,assertSubset)
166176
importFrom(coop,pcor)
177+
importFrom(data.table,":=")
178+
importFrom(data.table,as.data.table)
179+
importFrom(data.table,data.table)
180+
importFrom(data.table,merge.data.table)
181+
importFrom(data.table,tstrsplit)
167182
importFrom(downloader,download)
168183
importFrom(grDevices,dev.off)
169184
importFrom(grDevices,palette)
@@ -211,6 +226,8 @@ importFrom(utils,sessionInfo)
211226
importFrom(utils,setTxtProgressBar)
212227
importFrom(utils,txtProgressBar)
213228
importFrom(utils,write.table)
229+
importMethodsFrom(BiocGenerics,"annotation<-")
230+
importMethodsFrom(BiocGenerics,annotation)
214231
importMethodsFrom(CoreGx,"annotation<-")
215232
importMethodsFrom(CoreGx,"curation<-")
216233
importMethodsFrom(CoreGx,"datasetType<-")

R/methods-View.R

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#' Guarded View for CoreSet/PharmacoSet
2+
#'
3+
#' Emits the same compatibility error as `CoreGx::show()` and stops for
4+
#' outdated CoreSet-derived objects. Otherwise delegates to whatever
5+
#' `utils::View` is installed in `package:utils` (RStudio/Positron override
6+
#' or base).
7+
#'
8+
#' @param x Any R object, typically a data.frame-like or `CoreSet`-derived.
9+
#' @param title Optional title for the data viewer.
10+
#'
11+
#' @return Invisibly returns whatever the underlying viewer returns.
12+
#' @seealso [utils::View()]
13+
#'
14+
#' @examples
15+
#' if (interactive()) {
16+
#' data("CCLEsmall", package = "PharmacoGx")
17+
#' View(CCLEsmall)
18+
#' }
19+
#'
20+
#' @export
21+
View <- function(x, title = NULL) {
22+
# Only intercept for CoreSet-derived objects; keep everything else untouched
23+
if (methods::is(x, "CoreSet")) {
24+
# Replicate CoreGx::show() outdated check (CoreGx/R/CoreSet-class.R:424-428)
25+
hasSample <- methods::.hasSlot(x, "sample")
26+
hasTreatment <- methods::.hasSlot(x, "treatment")
27+
if (!(hasSample && hasTreatment)) {
28+
# Hard stop with the same message as CoreGx::show()
29+
stop(
30+
CoreGx::.errorMsg(
31+
"This ",
32+
class(x)[1],
33+
" object appears to be out of date! ",
34+
"Please run object <- updateObject(object) to update ",
35+
"the object for compatibility with the current release."
36+
),
37+
call. = FALSE
38+
)
39+
}
40+
}
41+
42+
# Ensure Positron/RStudio/base receive a scalar string title
43+
if (missing(title) || is.null(title)) {
44+
title2 <- base::deparse(substitute(x))
45+
} else {
46+
title2 <- base::as.character(title)[1]
47+
if (is.na(title2)) title2 <- base::deparse(substitute(x))
48+
}
49+
50+
# Delegate to whatever View is installed in package:utils
51+
get("View", envir = as.environment("package:utils"))(x, title2)
52+
}

man/View.Rd

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)