I have tried to figure out actual memory requirements for storing particular object. I tried two methods:
object.size(obj)
save(obj, file = "obj.Rdata") and checking the file size.
The .Rdata file is compressed so it was always smaller than what object.size() has returned, until I saw this object:
> object.size(out)
144792 bytes
> save(out, file = "out.Rdata")
# the file has 211 759 bytes
When I open the file in new R and run object.size(out), it reports 144792 bytes again.
Any idea how this can happen?
I don't want to post the complete object here since it contains closed data, but I can post the str output at least (it is the output of the R2jags::jags call - object of class rjags):
> str(out)
List of 6
$ model :List of 8
..$ ptr :function ()
..$ data :function ()
..$ model :function ()
..$ state :function (internal = FALSE)
..$ nchain :function ()
..$ iter :function ()
..$ sync :function ()
..$ recompile:function ()
..- attr(*, "class")= chr "jags"
$ BUGSoutput :List of 24
..$ n.chains : int 2
..$ n.iter : num 1000
..$ n.burnin : num 500
..$ n.thin : num 1
..$ n.keep : int 500
..$ n.sims : int 1000
..$ sims.array : num [1:500, 1:2, 1:5] -5.86e-06 -3.78e-02 6.92e-02 4.33e-02 4.34e-02 ...
.. ..- attr(*, "dimnames")=List of 3
.. .. ..$ : NULL
.. .. ..$ : NULL
.. .. ..$ : chr [1:5] "alpha" "beta" "deviance" "overdisp_sigma" ...
..$ sims.list :List of 5
.. ..$ alpha : num [1:1000, 1] 0.04702 -0.00818 0.03757 0.00799 0.00369 ...
.. ..$ beta : num [1:1000, 1] -0.135 -0.2082 -0.0112 -0.129 -0.1613 ...
.. ..$ deviance : num [1:1000, 1] 16028 22052 16127 16057 16141 ...
.. ..$ overdisp_sigma: num [1:1000, 1] 0.26506 0.00821 0.24998 0.25793 0.26013 ...
.. ..$ yr_reff_sigma : num [1:1000, 1] 0.1581 0.176 0.0695 0.1052 0.1043 ...
..$ sims.matrix : num [1:1000, 1:5] 0.04702 -0.00818 0.03757 0.00799 0.00369 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:5] "alpha" "beta" "deviance" "overdisp_sigma" ...
..$ summary : num [1:5, 1:9] 3.16e-03 -1.20e-01 1.68e+04 2.29e-01 1.19e-01 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:5] "alpha" "beta" "deviance" "overdisp_sigma" ...
.. .. ..$ : chr [1:9] "mean" "sd" "2.5%" "25%" ...
..$ mean :List of 5
.. ..$ alpha : num [1(1d)] 0.00316
.. ..$ beta : num [1(1d)] -0.12
.. ..$ deviance : num [1(1d)] 16835
.. ..$ overdisp_sigma: num [1(1d)] 0.229
.. ..$ yr_reff_sigma : num [1(1d)] 0.119
..$ sd :List of 5
.. ..$ alpha : num [1(1d)] 0.0403
.. ..$ beta : num [1(1d)] 0.0799
.. ..$ deviance : num [1(1d)] 2378
.. ..$ overdisp_sigma: num [1(1d)] 0.0702
.. ..$ yr_reff_sigma : num [1(1d)] 0.036
..$ median :List of 5
.. ..$ alpha : num [1(1d)] 0.00399
.. ..$ beta : num [1(1d)] -0.123
.. ..$ deviance : num [1(1d)] 16209
.. ..$ overdisp_sigma: num [1(1d)] 0.252
.. ..$ yr_reff_sigma : num [1(1d)] 0.111
..$ root.short : chr [1:5] "alpha" "beta" "deviance" "overdisp_sigma" ...
..$ long.short :List of 5
.. ..$ : int 1
.. ..$ : int 2
.. ..$ : int 3
.. ..$ : int 4
.. ..$ : int 5
..$ dimension.short: num [1:5] 0 0 0 0 0
..$ indexes.short :List of 5
.. ..$ : NULL
.. ..$ : NULL
.. ..$ : NULL
.. ..$ : NULL
.. ..$ : NULL
..$ last.values :List of 2
.. ..$ :List of 4
.. .. ..$ alpha : num [1(1d)] 0.0296
.. .. ..$ beta : num [1(1d)] -0.0964
.. .. ..$ deviance : num [1(1d)] 16113
.. .. ..$ overdisp_sigma: num [1(1d)] 0.265
.. ..$ :List of 4
.. .. ..$ alpha : num [1(1d)] 0.0334
.. .. ..$ beta : num [1(1d)] -0.228
.. .. ..$ deviance : num [1(1d)] 16139
.. .. ..$ overdisp_sigma: num [1(1d)] 0.257
..$ program : chr "jags"
..$ model.file : chr "model.txt"
..$ isDIC : logi TRUE
..$ DICbyR : logi TRUE
..$ pD : num 2830902
..$ DIC : num 2847738
..- attr(*, "class")= chr "bugs"
$ parameters.to.save: chr [1:5] "alpha" "beta" "overdisp_sigma" "yr_reff_sigma" ...
$ model.file : chr "model.txt"
$ n.iter : num 1000
$ DIC : logi TRUE
- attr(*, "class")= chr "rjags"
One way this can happen is if the object has an associated environment that needs saving with it if it is to make sense. This comes up most commonly in the context of "closures" (see here for one explanation).
Without a reproducible example (and without having used R2jags myself) I can't tell you whether that's what is going on in your case, but it at least seems plausible, given that: (a) closures seem to be the most common cause of this situation; (b) based on the output of str(out), your object seems to include a bunch of functions; and (c) it seems like this might be a useful way to organize a computation-heavy and possibly parallelizable procedure like MCMC.
## Define a function "f" that returns a closure, here assigned to the object "y"
f <- function() {
x <- 1:1e6
function() 2*x
}
y <- f()
environment(y)
# <environment: 0x0000000008409ab8>
object.size(y)
# 1216 bytes
save(y, file="out.Rdata")
file.info("out.Rdata")$size
# [1] 2128554
Related
I want to know how can I access, extract, and reference values from a plotly figure in R.
Consider, for example, the Sankey diagram from plotly's own site of which there is an abbreviated version here:
library(plotly)
fig <- plot_ly(
type = "sankey",
node = list(
label = c("A1", "A2", "B1", "B2", "C1", "C2"),
color = c("blue", "blue", "blue", "blue", "blue", "blue"),
line = list()
),
link = list(
source = c(0,1,0,2,3,3),
target = c(2,3,3,4,4,5),
value = c(8,4,2,8,4,2)
)
)
fig
If I do View(fig) in Rstudio, a new tab opens titled . (I don't know why this instead of 'fig'). In this tab I can go to x > visdat > 'strig of letters and numbers that is a function?' > attrs > node > x (as shown bellow).
Here all the x coordinates for the Sankey nodes appear.
I want to access these values so I can use them somewhere else. How do I do this? If I click on the right side of the Rsutudio tab to copy the code to console I get:
environment(.[["x"]][["visdat"]][["484c3ec36899"]])[["attrs"]][["node"]][["x"]]
which obviously doesn't work as there is no object named ..
In this case I have tried fig$x$visdat$`484c3ec36899`() but I cant do fig$x$visdat$`484c3ec36899`()$attr, and I don't know what else to do.
So, how can I access any value from a plotly object? Any documentation referencing this topic would also be helpful.
Thanks.
You can find the documentation of the data structure of plotly in R here: https://plotly.com/r/figure-structure/
To check the data structure you can use str(fig):
List of 8
$ x :List of 6
..$ visdat :List of 1
.. ..$ a3b8795a4:function ()
..$ cur_data: chr "a3b8795a4"
..$ attrs :List of 1
.. ..$ a3b8795a4:List of 6
.. .. ..$ node :List of 3
.. .. .. ..$ label: chr [1:6] "A1" "A2" "B1" "B2" ...
.. .. .. ..$ color: chr [1:6] "blue" "blue" "blue" "blue" ...
.. .. .. ..$ line : list()
.. .. ..$ link :List of 3
.. .. .. ..$ source: num [1:6] 0 1 0 2 3 3
.. .. .. ..$ target: num [1:6] 2 3 3 4 4 5
.. .. .. ..$ value : num [1:6] 8 4 2 8 4 2
.. .. ..$ alpha_stroke: num 1
.. .. ..$ sizes : num [1:2] 10 100
.. .. ..$ spans : num [1:2] 1 20
.. .. ..$ type : chr "sankey"
..$ layout :List of 3
.. ..$ width : NULL
.. ..$ height: NULL
.. ..$ margin:List of 4
.. .. ..$ b: num 40
.. .. ..$ l: num 60
.. .. ..$ t: num 25
.. .. ..$ r: num 10
..$ source : chr "A"
..$ config :List of 1
.. ..$ showSendToCloud: logi FALSE
..- attr(*, "TOJSON_FUNC")=function (x, ...)
$ width : NULL
$ height : NULL
$ sizingPolicy :List of 6
..$ defaultWidth : chr "100%"
..$ defaultHeight: num 400
..$ padding : NULL
..$ viewer :List of 6
.. ..$ defaultWidth : NULL
.. ..$ defaultHeight: NULL
.. ..$ padding : NULL
.. ..$ fill : logi TRUE
.. ..$ suppress : logi FALSE
.. ..$ paneHeight : NULL
..$ browser :List of 5
.. ..$ defaultWidth : NULL
.. ..$ defaultHeight: NULL
.. ..$ padding : NULL
.. ..$ fill : logi TRUE
.. ..$ external : logi FALSE
..$ knitr :List of 3
.. ..$ defaultWidth : NULL
.. ..$ defaultHeight: NULL
.. ..$ figure : logi TRUE
$ dependencies :List of 5
..$ :List of 10
.. ..$ name : chr "typedarray"
.. ..$ version : chr "0.1"
.. ..$ src :List of 1
.. .. ..$ file: chr "htmlwidgets/lib/typedarray"
.. ..$ meta : NULL
.. ..$ script : chr "typedarray.min.js"
.. ..$ stylesheet: NULL
.. ..$ head : NULL
.. ..$ attachment: NULL
.. ..$ package : chr "plotly"
.. ..$ all_files : logi FALSE
.. ..- attr(*, "class")= chr "html_dependency"
..$ :List of 10
.. ..$ name : chr "jquery"
.. ..$ version : chr "1.11.3"
.. ..$ src :List of 1
.. .. ..$ file: chr "lib/jquery"
.. ..$ meta : NULL
.. ..$ script : chr "jquery.min.js"
.. ..$ stylesheet: NULL
.. ..$ head : NULL
.. ..$ attachment: NULL
.. ..$ package : chr "crosstalk"
.. ..$ all_files : logi TRUE
.. ..- attr(*, "class")= chr "html_dependency"
..$ :List of 10
.. ..$ name : chr "crosstalk"
.. ..$ version : chr "1.1.0.1"
.. ..$ src :List of 1
.. .. ..$ file: chr "www"
.. ..$ meta : NULL
.. ..$ script : chr "js/crosstalk.min.js"
.. ..$ stylesheet: chr "css/crosstalk.css"
.. ..$ head : NULL
.. ..$ attachment: NULL
.. ..$ package : chr "crosstalk"
.. ..$ all_files : logi TRUE
.. ..- attr(*, "class")= chr "html_dependency"
..$ :List of 10
.. ..$ name : chr "plotly-htmlwidgets-css"
.. ..$ version : chr "1.52.2"
.. ..$ src :List of 1
.. .. ..$ file: chr "htmlwidgets/lib/plotlyjs"
.. ..$ meta : NULL
.. ..$ script : NULL
.. ..$ stylesheet: chr "plotly-htmlwidgets.css"
.. ..$ head : NULL
.. ..$ attachment: NULL
.. ..$ package : chr "plotly"
.. ..$ all_files : logi FALSE
.. ..- attr(*, "class")= chr "html_dependency"
..$ :List of 10
.. ..$ name : chr "plotly-main"
.. ..$ version : chr "1.52.2"
.. ..$ src :List of 1
.. .. ..$ file: chr "htmlwidgets/lib/plotlyjs"
.. ..$ meta : NULL
.. ..$ script : chr "plotly-latest.min.js"
.. ..$ stylesheet: NULL
.. ..$ head : NULL
.. ..$ attachment: NULL
.. ..$ package : chr "plotly"
.. ..$ all_files : logi FALSE
.. ..- attr(*, "class")= chr "html_dependency"
$ elementId : NULL
$ preRenderHook:function (p, registerFrames = TRUE)
$ jsHooks : list()
- attr(*, "class")= chr [1:2] "plotly" "htmlwidget"
- attr(*, "package")= chr "plotly"
You could extract the coordinates with:
unlist(fig$x$attrs)
I have a list vector containing S4 correlation templates from the monitoR::makeCorTemplate function.
temps_0 <- vector(mode = 'list',length=length(tru_files_info_0$species_id))
for (j in 1: length(tru_files_info_0$species_id)) {
temps_0[j] <- MonitoR::makeCorTemplate(paste0('tru_tp_files','/',paste0(tru_files_info_0$recording_id[j],'',
'.wav')), t.lim =c(tru_files_info_0$t_min[j], tru_files_info_0$t_max[j]),
frq.lim = c(tru_files_info_0$f_min[j]/1000, tru_files_info_0$f_max[j]/1000),
select = 'auto', dens =1, score.cutoff = 0.2, name = tru_files_info_0$new_name[j])
+ }```
Resulting object
Formal class 'corTemplateList' [package "monitoR"] with 1 slot
..# templates:List of 1
.. ..$ 00d442df7_0:Formal class 'corTemplate' [package "monitoR"] with 15 slots
.. .. .. ..# clip.path : chr "tru_tp_files/00d442df7.wav"
.. .. .. ..# samp.rate : int 48000
.. .. .. ..# pts : num [1:1924, 1:3] 1 1 1 1 1 1 1 1 1 1 ...
.. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. ..$ : NULL
.. .. .. .. .. ..$ : chr [1:3] "t" "frq" "amp"
.. .. .. ..# t.step : num 0.0107
.. .. .. ..# frq.step : num 0.0938
.. .. .. ..# n.t.bins : int 73
.. .. .. ..# first.t.bin : num 19.4
.. .. .. ..# n.frq.bins : int 25
.. .. .. ..# duration : num 0.779
.. .. .. ..# frq.lim : num [1:2] 5.91 8.25
.. .. .. ..# wl : int 512
.. .. .. ..# ovlp : int 0
.. .. .. ..# wn : chr "hanning"
.. .. .. ..# score.cutoff: num 0.2
.. .. .. ..# comment : chr ""
The next processing step is to combine these 10 templates via combineCorTemplates:
> ctemps_0 <- monitoR::combineCorTemplates(temps_0[[1]], temps_0[[2]], temps_0[[3]], temps_0[[4]], temps_0[[5]], temps_0[[6]], temps_0[[7]], temps_0[[8]], temps_0[[9]], temps_0[[10]])
> ctemps_0
Object of class "corTemplateList"
containing 10 templates
original.recording sample.rate lower.frequency
00d442df7_0 tru_tp_files/00d442df7.wav 48000 5.906
0ea8ea68a_0 tru_tp_files/0ea8ea68a.wav 48000 5.906
2e40b2294_0 tru_tp_files/2e40b2294.wav 48000 5.906
45c356538_0 tru_tp_files/45c356538.wav 48000 5.906
My question, how to extract the S4 from the list vector without writing out
each list element as combineCorTemplates(temps_0[[1]], temps_0[[2]], & etc
as this is error prone.
We could use do.call
c_temps_0 <- do.call(monitoR::combineCorTemplates, temps_0)
-testing
c_temps_1 <- combineCorTemplates(temps_0[[1]], temps_0[[2]],
temps_0[[3]], temps_0[[4]])
identical(c_temps_0, c_temps_1)
#[1] TRUE
NOTE: The reproducible example is created from ?combineCorTemplates
I have tried to figure out actual memory requirements for storing particular object. I tried two methods:
object.size(obj)
save(obj, file = "obj.Rdata") and checking the file size.
The .Rdata file is compressed so it was always smaller than what object.size() has returned, until I saw this object:
> object.size(out)
144792 bytes
> save(out, file = "out.Rdata")
# the file has 211 759 bytes
When I open the file in new R and run object.size(out), it reports 144792 bytes again.
Any idea how this can happen?
I don't want to post the complete object here since it contains closed data, but I can post the str output at least (it is the output of the R2jags::jags call - object of class rjags):
> str(out)
List of 6
$ model :List of 8
..$ ptr :function ()
..$ data :function ()
..$ model :function ()
..$ state :function (internal = FALSE)
..$ nchain :function ()
..$ iter :function ()
..$ sync :function ()
..$ recompile:function ()
..- attr(*, "class")= chr "jags"
$ BUGSoutput :List of 24
..$ n.chains : int 2
..$ n.iter : num 1000
..$ n.burnin : num 500
..$ n.thin : num 1
..$ n.keep : int 500
..$ n.sims : int 1000
..$ sims.array : num [1:500, 1:2, 1:5] -5.86e-06 -3.78e-02 6.92e-02 4.33e-02 4.34e-02 ...
.. ..- attr(*, "dimnames")=List of 3
.. .. ..$ : NULL
.. .. ..$ : NULL
.. .. ..$ : chr [1:5] "alpha" "beta" "deviance" "overdisp_sigma" ...
..$ sims.list :List of 5
.. ..$ alpha : num [1:1000, 1] 0.04702 -0.00818 0.03757 0.00799 0.00369 ...
.. ..$ beta : num [1:1000, 1] -0.135 -0.2082 -0.0112 -0.129 -0.1613 ...
.. ..$ deviance : num [1:1000, 1] 16028 22052 16127 16057 16141 ...
.. ..$ overdisp_sigma: num [1:1000, 1] 0.26506 0.00821 0.24998 0.25793 0.26013 ...
.. ..$ yr_reff_sigma : num [1:1000, 1] 0.1581 0.176 0.0695 0.1052 0.1043 ...
..$ sims.matrix : num [1:1000, 1:5] 0.04702 -0.00818 0.03757 0.00799 0.00369 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:5] "alpha" "beta" "deviance" "overdisp_sigma" ...
..$ summary : num [1:5, 1:9] 3.16e-03 -1.20e-01 1.68e+04 2.29e-01 1.19e-01 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:5] "alpha" "beta" "deviance" "overdisp_sigma" ...
.. .. ..$ : chr [1:9] "mean" "sd" "2.5%" "25%" ...
..$ mean :List of 5
.. ..$ alpha : num [1(1d)] 0.00316
.. ..$ beta : num [1(1d)] -0.12
.. ..$ deviance : num [1(1d)] 16835
.. ..$ overdisp_sigma: num [1(1d)] 0.229
.. ..$ yr_reff_sigma : num [1(1d)] 0.119
..$ sd :List of 5
.. ..$ alpha : num [1(1d)] 0.0403
.. ..$ beta : num [1(1d)] 0.0799
.. ..$ deviance : num [1(1d)] 2378
.. ..$ overdisp_sigma: num [1(1d)] 0.0702
.. ..$ yr_reff_sigma : num [1(1d)] 0.036
..$ median :List of 5
.. ..$ alpha : num [1(1d)] 0.00399
.. ..$ beta : num [1(1d)] -0.123
.. ..$ deviance : num [1(1d)] 16209
.. ..$ overdisp_sigma: num [1(1d)] 0.252
.. ..$ yr_reff_sigma : num [1(1d)] 0.111
..$ root.short : chr [1:5] "alpha" "beta" "deviance" "overdisp_sigma" ...
..$ long.short :List of 5
.. ..$ : int 1
.. ..$ : int 2
.. ..$ : int 3
.. ..$ : int 4
.. ..$ : int 5
..$ dimension.short: num [1:5] 0 0 0 0 0
..$ indexes.short :List of 5
.. ..$ : NULL
.. ..$ : NULL
.. ..$ : NULL
.. ..$ : NULL
.. ..$ : NULL
..$ last.values :List of 2
.. ..$ :List of 4
.. .. ..$ alpha : num [1(1d)] 0.0296
.. .. ..$ beta : num [1(1d)] -0.0964
.. .. ..$ deviance : num [1(1d)] 16113
.. .. ..$ overdisp_sigma: num [1(1d)] 0.265
.. ..$ :List of 4
.. .. ..$ alpha : num [1(1d)] 0.0334
.. .. ..$ beta : num [1(1d)] -0.228
.. .. ..$ deviance : num [1(1d)] 16139
.. .. ..$ overdisp_sigma: num [1(1d)] 0.257
..$ program : chr "jags"
..$ model.file : chr "model.txt"
..$ isDIC : logi TRUE
..$ DICbyR : logi TRUE
..$ pD : num 2830902
..$ DIC : num 2847738
..- attr(*, "class")= chr "bugs"
$ parameters.to.save: chr [1:5] "alpha" "beta" "overdisp_sigma" "yr_reff_sigma" ...
$ model.file : chr "model.txt"
$ n.iter : num 1000
$ DIC : logi TRUE
- attr(*, "class")= chr "rjags"
One way this can happen is if the object has an associated environment that needs saving with it if it is to make sense. This comes up most commonly in the context of "closures" (see here for one explanation).
Without a reproducible example (and without having used R2jags myself) I can't tell you whether that's what is going on in your case, but it at least seems plausible, given that: (a) closures seem to be the most common cause of this situation; (b) based on the output of str(out), your object seems to include a bunch of functions; and (c) it seems like this might be a useful way to organize a computation-heavy and possibly parallelizable procedure like MCMC.
## Define a function "f" that returns a closure, here assigned to the object "y"
f <- function() {
x <- 1:1e6
function() 2*x
}
y <- f()
environment(y)
# <environment: 0x0000000008409ab8>
object.size(y)
# 1216 bytes
save(y, file="out.Rdata")
file.info("out.Rdata")$size
# [1] 2128554
Although I understand OOP, I've only just encountered them in R
I am using a package from Bioconductor to churn through some genomic data.
The object it creates is called readCounts and typing this into the command gives the following.
QDNAseqReadCounts (storageMode: lockedEnvironment)
assayData: 206391 features, 1 samples
element names: counts
protocolData: none
phenoData
sampleNames: SLX-10457.FastSeqA.BloodDMets_11AF_-AHMMH.s_1.r_1.fq.gz
varLabels: name total.reads used.reads expected.variance
varMetadata: labelDescription
featureData
featureNames: 1:825001-840000 1:840001-855000 ... 22:51165001-51180000 (168063 total)
fvarLabels: chromosome start ... use (9 total)
fvarMetadata: labelDescription
experimentData: use 'experimentData(object)'
Annotation:
I am trying to plot readcounts on a simple xy graph as follows:
plot(readCounts, logTransform=TRUE, ylim=c(-1000, binSize * 15))
However when I do so I get the following error:
Error in sort.int(x, partial = unique(c(lo, hi))) :
index 180 outside bounds
with the traceback() showing:
6: sort.int(x, partial = unique(c(lo, hi)))
5: FUN(newX[, i], ...)
4: apply(copynumber, 2, sdFUN, na.rm = TRUE)
3: .local(x, y, ...)
2: plot(readCounts, logTransform = TRUE, ylim = c(-1000, binSize *
15))
1: plot(readCounts, logTransform = TRUE, ylim = c(-1000, binSize *
15))
so having googled I thought it might be a missing values problem so I tried na.omit(readCounts) but got the same error again but this time setting the out of bounds index as being 207.
I have tried to inspect the data but I can't find anything wrong at row 207 although I'm not really sure which slot this refers to. I really don't know how to debug this. I'm happy to give more info regarding what I'm trying to do but I don't really know how to determine what the problem is with this error in a R object.
When I do str(readCounts) I get:
Formal class 'QDNAseqReadCounts' [package "QDNAseq"] with 7 slots
..# assayData :<environment: 0x13a99ed90>
..# phenoData :Formal class 'AnnotatedDataFrame' [package "Biobase"] with 4 slots
.. .. ..# varMetadata :'data.frame': 4 obs. of 1 variable:
.. .. .. ..$ labelDescription: chr [1:4] NA NA NA NA
.. .. ..# data :'data.frame': 1 obs. of 4 variables:
.. .. .. ..$ name : chr "SLX-10457.FastSeqA.BloodDMets_11AF_-AHMMH.s_1.r_1.fq.gz"
.. .. .. ..$ total.reads : num 0
.. .. .. ..$ used.reads : num 0
.. .. .. ..$ expected.variance: num Inf
.. .. ..# dimLabels : chr [1:2] "sampleNames" "sampleColumns"
.. .. ..# .__classVersion__:Formal class 'Versions' [package "Biobase"] with 1 slot
.. .. .. .. ..# .Data:List of 1
.. .. .. .. .. ..$ : int [1:3] 1 1 0
..# featureData :Formal class 'AnnotatedDataFrame' [package "Biobase"] with 4 slots
.. .. ..# varMetadata :'data.frame': 9 obs. of 1 variable:
.. .. .. ..$ labelDescription: chr [1:9] "Chromosome name" "Base pair start position" "Base pair end position" "Percentage of non-N nucleotides (of full bin size)" ...
.. .. ..# data :'data.frame': 168063 obs. of 9 variables:
.. .. .. ..$ chromosome : chr [1:168063] "1" "1" "1" "1" ...
.. .. .. ..$ start : num [1:168063] 825001 840001 855001 870001 885001 ...
.. .. .. ..$ end : num [1:168063] 840000 855000 870000 885000 900000 915000 930000 945000 960000 975000 ...
.. .. .. ..$ bases : num [1:168063] 100 100 100 100 100 100 100 100 100 100 ...
.. .. .. ..$ gc : num [1:168063] 48 61.8 65.1 65.5 62.6 ...
.. .. .. ..$ mappability: num [1:168063] 58.6 91.5 94.1 93.2 93.9 ...
.. .. .. ..$ blacklist : num [1:168063] 0.727 0 0 0 0 ...
.. .. .. ..$ residual : num [1:168063] -0.0627 0.05036 0.09384 0.00541 -0.00588 ...
.. .. .. ..$ use : logi [1:168063] TRUE TRUE TRUE TRUE TRUE TRUE ...
.. .. .. ..- attr(*, "na.action")=Class 'omit' Named int [1:38328] 1 2 3 4 5 6 7 8 9 10 ...
.. .. .. .. .. ..- attr(*, "names")= chr [1:38328] "1:1-15000" "1:15001-30000" "1:30001-45000" "1:45001-60000" ...
.. .. ..# dimLabels : chr [1:2] "featureNames" "featureColumns"
.. .. ..# .__classVersion__:Formal class 'Versions' [package "Biobase"] with 1 slot
.. .. .. .. ..# .Data:List of 1
.. .. .. .. .. ..$ : int [1:3] 1 1 0
..# experimentData :Formal class 'MIAME' [package "Biobase"] with 13 slots
.. .. ..# name : chr ""
.. .. ..# lab : chr ""
.. .. ..# contact : chr ""
.. .. ..# title : chr ""
.. .. ..# abstract : chr ""
.. .. ..# url : chr ""
.. .. ..# pubMedIds : chr ""
.. .. ..# samples : list()
.. .. ..# hybridizations : list()
.. .. ..# normControls : list()
.. .. ..# preprocessing : list()
.. .. ..# other : list()
.. .. ..# .__classVersion__:Formal class 'Versions' [package "Biobase"] with 1 slot
.. .. .. .. ..# .Data:List of 2
.. .. .. .. .. ..$ : int [1:3] 1 0 0
.. .. .. .. .. ..$ : int [1:3] 1 1 0
..# annotation : chr(0)
..# protocolData :Formal class 'AnnotatedDataFrame' [package "Biobase"] with 4 slots
.. .. ..# varMetadata :'data.frame': 0 obs. of 1 variable:
.. .. .. ..$ labelDescription: chr(0)
.. .. ..# data :'data.frame': 1 obs. of 0 variables
.. .. ..# dimLabels : chr [1:2] "sampleNames" "sampleColumns"
.. .. ..# .__classVersion__:Formal class 'Versions' [package "Biobase"] with 1 slot
.. .. .. .. ..# .Data:List of 1
.. .. .. .. .. ..$ : int [1:3] 1 1 0
..# .__classVersion__:Formal class 'Versions' [package "Biobase"] with 1 slot
.. .. ..# .Data:List of 4
.. .. .. ..$ : int [1:3] 3 1 2
.. .. .. ..$ : int [1:3] 2 26 0
.. .. .. ..$ : int [1:3] 1 3 0
.. .. .. ..$ : int [1:3] 1 2 4
I have the following object M, from which I need to extract the fstatistic. It is a model generated by the function summaryC of a model generated by aovp, both functions from package lmPerm. I have tried hints for extracting values from normal linear models and from the functions in attr, extract and getElement, but without success.
Anybody could give me a hint?
> str(M)
List of 2
$ Error: vegetation: NULL
$ Error: Within :List of 11
..$ NA : NULL
..$ terms :Classes 'terms', 'formula' length 3 Temp ~ depth
.. .. ..- attr(*, "variables")= language list(Temp, depth)
.. .. ..- attr(*, "factors")= int [1:2, 1] 0 1
.. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. ..$ : chr [1:2] "Temp" "depth"
.. .. .. .. ..$ : chr "depth"
.. .. ..- attr(*, "term.labels")= chr "depth"
.. .. ..- attr(*, "order")= int 1
.. .. ..- attr(*, "intercept")= int 1
.. .. ..- attr(*, "response")= int 1
.. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
..$ residuals : Named num [1:498] -46.9 -43.9 -46.9 -38.9 -41.9 ...
.. ..- attr(*, "names")= chr [1:498] "3" "4" "5" "6" ...
..$ coefficients : num [1:4, 1:4] -2.00 -1.00 -1.35e-14 1.00 2.59 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:4] "depth1" "depth2" "depth3" "depth4"
.. .. ..$ : chr [1:4] "Estimate" "Std. Error" "t value" "Pr(>|t|)"
..$ aliased : Named logi [1:4] FALSE FALSE FALSE FALSE
.. ..- attr(*, "names")= chr [1:4] "depth1" "depth2" "depth3" "depth4"
..$ sigma : num 29
..$ df : int [1:3] 4 494 4
..$ r.squared : num 0.00239
..$ adj.r.squared: num -0.00367
..$ **fstatistic** : Named num [1:3] 0.395 3 494
.. ..- attr(*, "names")= chr [1:3] "value" "numdf" "dendf"
..$ cov.unscaled : num [1:4, 1:4] 0.008 -0.002 -0.002 -0.002 -0.002 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:4] "depth1" "depth2" "depth3" "depth4"
.. .. ..$ : chr [1:4] "depth1" "depth2" "depth3" "depth4"
..- attr(*, "class")= chr "summary.lmp"
- attr(*, "class")= chr "listof"
there it goes a reproducible example to play with:
Temp=1:100
depth<- rep( c("1","2","3","4","5"), 100)
vegetation=rep( c("1","2"), 50)
df=data.frame(Temp,depth,vegetation)
M=summaryC(aovp(Temp~depth+Error(vegetation),df, perm=""))
as the str output from your example shows, M is a list of two lists, the second one contains what you want. Hence list extraction via [[ does the trick:
> M[[2]][["fstatistic"]]
value numdf dendf
0.3946 3.0000 494.0000
If this is not what you want, please comment.