Suppressing readOGR Messages in knitr [duplicate] - r

This question already has answers here:
In R and knitr, can I suppress the message of readOGR?
(3 answers)
Closed 7 years ago.
I wonder how to suppress readOGR error messages in knitr. My MWE is below:
\documentclass{article}
\begin{document}
<< Test >>=
library(rgdal)
dsn <- system.file("vectors", package = "rgdal")[1]
setwd(dsn)
cities <- readOGR(dsn=dsn, layer="cities")
#
\end{document}
The function readOGR gives the message like this:
OGR data source with driver: ESRI Shapefile
Source: "/home/asd/R/i686-pc-linux-gnu-library/3.2/rgdal/vectors", layer: "cities"
with 606 features
It has 4 fields
But I want to suppress this message. I tried message=FALSE, but it did not work for me.
Edited
sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: i686-pc-linux-gnu (32-bit)
Running under: Ubuntu 14.04.2 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] grid tools stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggmap_2.4 mapproj_1.2-2 maps_2.3-9 leaflet_1.0.0 rgeos_0.3-11 rgdal_1.0-4
[7] maptools_0.8-36 sp_1.1-1 Hmisc_3.16-0 Formula_1.2-1 survival_2.38-2 lattice_0.20-31
[13] psych_1.5.4 ggbiplot_0.55 plyr_1.8.3 gplots_2.17.0 rsm_2.7-2 scales_0.2.5
[19] ggplot2_1.0.1 xtable_1.7-4 highr_0.5 knitr_1.10.12 brew_1.0-6 stringr_1.0.0
loaded via a namespace (and not attached):
[1] RColorBrewer_1.1-2 jsonlite_0.9.16 reshape2_1.4.1 cluster_2.0.2 rstudioapi_0.3.1
[6] magrittr_1.5 acepack_1.3-3.3 gtable_0.1.2 htmltools_0.2.6 splines_3.2.1
[11] dplyr_0.4.2 KernSmooth_2.23-14 htmlwidgets_0.5 gridExtra_0.9.1 R6_2.0.1
[16] digest_0.6.8 colorspace_1.2-6 proto_0.3-10 stringi_0.5-2 yaml_2.1.13
[21] lazyeval_0.1.10.9000 evaluate_0.7 labeling_0.3 RJSONIO_1.3-0 gdata_2.16.1
[26] rpart_4.1-9 munsell_0.4.2 DBI_0.3.1 Rcpp_0.11.6 RgoogleMaps_1.2.0.7
[31] png_0.1-7 MASS_7.3-41 parallel_3.2.1 assertthat_0.1 rjson_0.2.15
[36] caTools_1.17.1 gtools_3.5.0 jpeg_0.1-8 latticeExtra_0.6-26 foreign_0.8-63
[41] bitops_1.0-6 nnet_7.3-9 geosphere_1.3-13 formatR_1.2 mnormt_1.5-3

Just add verbose=FALSE to the readOGR call to suppress the messages (which are helpful during an interactive session but are cruft when in scripts or notebooks).

Try this:
<<Test, message=FALSE, results='hide', echo=FALSE>>=

Related

RMarkdown: preserve source code formatting in code cell

My Rmarkdown source looks like (screenshot from RStudio):
(notice the empty lines)
When I press CTRL+Shift+k I got view as expected (with empty lines). However, if I run the chunk (evaluate) and then compile (CTRL+Shift+k), I get:
(no empty lines)
Is there any way how to preserve the empty lines in the source code? (I checked knitr options: strip.white=FALSE, tidy=TRUE, tidy.opts=list(blank=TRUE) but no joy.)
I'm using RStudio 1.0.153
Other info:
sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.19.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rvest_0.3.2 xml2_1.1.1 dplyr_0.7.1 purrr_0.2.2.2
[5] readr_1.1.1 tidyr_0.6.3 tibble_1.3.3 ggplot2_2.2.1
[9] tidyverse_1.1.1
loaded via a namespace (and not attached):
[1] pbdZMQ_0.2-6 reshape2_1.4.2 haven_1.1.0 lattice_0.20-35
[5] colorspace_1.3-2 htmltools_0.3.6 yaml_2.1.14 base64enc_0.1-3
[9] XML_3.98-1.9 rlang_0.1.1 foreign_0.8-69 glue_1.1.1
[13] selectr_0.3-1 readxl_1.0.0 modelr_0.1.0 semver_0.2.0
[17] bindrcpp_0.2 bindr_0.1 plyr_1.8.4 stringr_1.2.0
[21] cellranger_1.1.0 munsell_0.4.3 binman_0.1.0 gtable_0.2.0
[25] caTools_1.17.1 psych_1.7.5 evaluate_0.10.1 knitr_1.16
[29] forcats_0.2.0 wdman_0.2.2 curl_2.7 parallel_3.4.1
[33] broom_0.4.2 Rcpp_0.12.11 openssl_0.9.6 backports_1.1.0
[37] scales_0.4.1 formatR_1.5 RSelenium_1.7.1 jsonlite_1.5
[41] mnormt_1.5-5 hms_0.3 digest_0.6.12 stringi_1.1.5
[45] grid_3.4.1 rprojroot_1.2 tools_3.4.1 bitops_1.0-6
[49] magrittr_1.5 lazyeval_0.2.0 pkgconfig_2.0.1 lubridate_1.6.0
[53] httr_1.2.1 assertthat_0.2.0 rmarkdown_1.6 R6_2.2.2
[57] nlme_3.1-131 compiler_3.4.1
As far as I can see, you can't do that with an HTML notebook. If you don't need all the special notebook features, you can ask for an html_document instead of an html_notebook and formatting will be preserved. If you do need the notebook features, you probably need to make a feature request on the rmarkdown development page https://github.com/rstudio/rmarkdown to add this.

Error when Using BiomartGeneRegionTrack in cummeRbund package

I am trying to plot a gene of interest using cummeRbund package. Using this script:
biomTrack<-BiomartGeneRegionTrack(genome=genome, chromosome=as.character(myChr), start=myStart, end=myEnd, name="ENSEMBL", showId=T)
I encountered this error:
Error in .getBiomart(genome) :
Gviz thinks that the UCSC genome identifier 'hg38' should map to the current Biomart head as 'GRCh38', but its current version is 'GRCh38.p5'.
Please manually provide biomaRt object.
using useMart("ensembl",dataset="hsapiens_gene_ensembl") also couldn't help. Would you please tell me how can I fix this?
Here is the sessionInfo()
> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] grid stats4 parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] biomaRt_2.28.0 cummeRbund_2.14.0 Gviz_1.16.1 rtracklayer_1.32.1 GenomicRanges_1.24.2
[6] GenomeInfoDb_1.8.1 IRanges_2.6.0 S4Vectors_0.10.1 fastcluster_1.1.20 reshape2_1.4.1
[11] ggplot2_2.1.0 RSQLite_1.0.0 DBI_0.4-1 BiocGenerics_0.18.0
loaded via a namespace (and not attached):
[1] SummarizedExperiment_1.2.3 VariantAnnotation_1.18.1 splines_3.3.0
[4] lattice_0.20-33 colorspace_1.2-6 htmltools_0.3.5
[7] GenomicFeatures_1.24.2 chron_2.3-47 interactiveDisplayBase_1.10.3
[10] XML_3.98-1.4 survival_2.39-4 foreign_0.8-66
[13] ensembldb_1.4.2 BiocParallel_1.6.2 RColorBrewer_1.1-2
[16] matrixStats_0.50.2 plyr_1.8.4 stringr_1.0.0
[19] zlibbioc_1.18.0 Biostrings_2.40.2 munsell_0.4.3
[22] gtable_0.2.0 latticeExtra_0.6-28 Biobase_2.32.0
[25] BiocInstaller_1.22.2 httpuv_1.3.3 AnnotationDbi_1.34.3
[28] Rcpp_0.12.5 xtable_1.8-2 acepack_1.3-3.3
[31] BSgenome_1.40.1 scales_0.4.0 Hmisc_3.17-4
[34] XVector_0.12.0 mime_0.4 Rsamtools_1.24.0
[37] gridExtra_2.2.1 AnnotationHub_2.4.2 digest_0.6.9
[40] stringi_1.1.1 biovizBase_1.20.0 shiny_0.13.2
[43] tools_3.3.0 bitops_1.0-6 magrittr_1.5
[46] RCurl_1.95-4.8 dichromat_2.0-0 Formula_1.2-1
[49] cluster_2.0.4 Matrix_1.2-6 data.table_1.9.6
[52] httr_1.2.0 R6_2.1.2 rpart_4.1-10
[55] GenomicAlignments_1.8.3 nnet_7.3-12

Error : object ‘sigma’ is not exported by 'namespace:lme4'

After updating lme4 (1.1-12), I'm getting this error when I invoke varComp package.
library(varComp)
Error : object ‘sigma’ is not exported by 'namespace:lme4'
Error: package or namespace load failed for ‘varComp’
Edited
Here is my sessionInfo()
sessionInfo()
R version 3.3.0 beta (2016-03-30 r70404)
Platform: i686-pc-linux-gnu (32-bit)
Running under: Ubuntu 14.04.3 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lme4_1.1-12 Matrix_1.2-4 devtools_1.11.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.4 Formula_1.2-1 roxygen2_5.0.1.9000 magrittr_1.5 cluster_2.0.3
[6] MASS_7.3-45 mutoss_0.1-10 splines_3.3.0 BiocGenerics_0.12.1 mnormt_1.5-4
[11] xtable_1.8-2 colorspace_1.2-6 lattice_0.20-33 R6_2.1.2 quadprog_1.5-5
[16] parallel_3.3.0 broom_0.4.0 latticeExtra_0.6-28 coda_0.18-1 TH.data_1.0-7
[21] withr_1.0.1 MatrixModels_0.4-1 assertthat_0.1 digest_0.6.9 multtest_2.22.0
[26] acepack_1.3-3.3 StroupGLMM_0.1.0 phia_0.2-1 scales_0.4.0 lsmeans_2.23
[31] Hmisc_3.17-3 lmerTest_2.0-30 stats4_3.3.0 survey_3.30-3 munsell_0.4.3
[36] multcomp_1.4-4 minqa_1.2.4 plyr_1.8.3 dplyr_0.4.3.9000 stringr_1.0.0
[41] car_2.1-2 tools_3.3.0 grid_3.3.0 nnet_7.3-12 pbkrtest_0.4-6
[46] nlme_3.1-127 Biobase_2.26.0 gtable_0.2.0 mgcv_1.8-12 quantreg_5.21
[51] psych_1.5.8 plotrix_3.6-1 DBI_0.3.1 survival_2.39-2 gridExtra_2.2.1
[56] ggplot2_2.1.0 tidyr_0.4.1 nloptr_1.0.4 reshape2_1.4.1 RColorBrewer_1.1-2
[61] codetools_0.2-14 rpart_4.1-10 aod_1.3 memoise_1.0.0 sandwich_2.3-4
[66] stringi_1.0-1 estimability_1.1-1 CompQuadForm_1.4.1 mvtnorm_1.0-5 SparseM_1.7
[71] foreign_0.8-66 zoo_1.7-12
The varComp package depends on RLRsim. RLRsim uses the S3 generic sigma, which was moved from lme4 to stats in R 3.3.0. If you use a Windows binary for RLRsim built under R < 3.3.0, then RLRsim will look for sigma in lme4 instead on in stats:
> install.packages("https://cran.r-project.org/bin/windows/contrib/3.2/RLRsim_3.1-2.zip", repos=NULL)
...
package ‘RLRsim’ successfully unpacked and MD5 sums checked
> library(varComp)
Error : object ‘sigma’ is not exported by 'namespace:lme4'
Error: package or namespace load failed for ‘varComp’
If you reinstall RLRsim you should get a recent build and varComp will load:
> install.packages("RLRsim")
...
package ‘RLRsim’ successfully unpacked and MD5 sums checked
...
> library(varComp)
>
I'm not sure if this is an answer or a workaround, but for me stating #' #imoprt package instead of #' #importFrom package function as an roxygen docstring did the trick. Faulty versioning, I guess...

plots not being printed in for loop when rendering PDF (since ggplot2 update)

I am attempting to render a PDF in which plots are outputted in a loop. The code I'm using previously worked as expected but now only the first plot in the loop is being printed in the pdf. The problem may be linked to the ggplot2 update (although I am not sure).
Below I have provided a reproducible example (as my rmarkdown file is far too long) which performs with the same error - printing only the first plot in the loop.
I may be missing something completely obvious of course! Any help greatly appreciated.
---
title: "Check"
output: pdf_document
---
```{r, results='asis'}
library(ggplot2)
Values = names(mtcars)[1:4]
mtcars$gear <- as.factor(mtcars$gear)
for(v in Values){
print(ggplot(mtcars, aes(x=carb, y = v, shape=gear)) + geom_point())
}
```
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252 LC_MONETARY=English_Ireland.1252 LC_NUMERIC=C
[5] LC_TIME=English_Ireland.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] HH_3.1-24 gridExtra_2.0.0 multcomp_1.4-1 TH.data_1.0-6 survival_2.38-3 mvtnorm_1.0-3 latticeExtra_0.6-26
[8] RColorBrewer_1.1-2 lattice_0.20-33 stringr_1.0.0 pander_0.6.0 xtable_1.8-0 ggplot2_2.0.0 rmarkdown_0.9.2
[15] markdown_0.7.7 knitr_1.12
loaded via a namespace (and not attached):
[1] zoo_1.7-12 reshape2_1.4.1 splines_3.2.3 colorspace_1.2-6 htmltools_0.3 yaml_2.1.13 gmp_0.5-12 foreign_0.8-66
[9] Rmpfr_0.6-0 plyr_1.8.3 munsell_0.4.2 gtable_0.1.2 leaps_2.9 codetools_0.2-14 evaluate_0.8 labeling_0.3
[17] httpuv_1.3.3 lmtest_0.9-34 vcd_1.4-1 proto_0.3-10 Rcpp_0.12.0 acepack_1.3-3.3 scales_0.3.0 formatR_1.2.1
[25] Hmisc_3.16-0 abind_1.4-3 mime_0.4 digest_0.6.9 stringi_1.0-1 shiny_0.13.0 tools_3.2.3 sandwich_2.3-3
[33] magrittr_1.5 Formula_1.2-1 cluster_2.0.3 MASS_7.3-45 R6_2.1.0 rpart_4.1-10 nnet_7.3-11 R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252 LC_MONETARY=English_Ireland.1252 LC_NUMERIC=C
[5] LC_TIME=English_Ireland.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] HH_3.1-24 gridExtra_2.0.0 multcomp_1.4-1 TH.data_1.0-6 survival_2.38-3 mvtnorm_1.0-3 latticeExtra_0.6-26
[8] RColorBrewer_1.1-2 lattice_0.20-33 stringr_1.0.0 pander_0.6.0 xtable_1.8-0 ggplot2_2.0.0 rmarkdown_0.9.2
[15] markdown_0.7.7 knitr_1.12
loaded via a namespace (and not attached):
[1] zoo_1.7-12 reshape2_1.4.1 splines_3.2.3 colorspace_1.2-6 htmltools_0.3 yaml_2.1.13 gmp_0.5-12 foreign_0.8-66
[9] Rmpfr_0.6-0 plyr_1.8.3 munsell_0.4.2 gtable_0.1.2 leaps_2.9 codetools_0.2-14 evaluate_0.8 labeling_0.3
[17] httpuv_1.3.3 lmtest_0.9-34 vcd_1.4-1 proto_0.3-10 Rcpp_0.12.0 acepack_1.3-3.3 scales_0.3.0 formatR_1.2.1
[25] Hmisc_3.16-0 abind_1.4-3 mime_0.4 digest_0.6.9 stringi_1.0-1 shiny_0.13.0 tools_3.2.3 sandwich_2.3-3
[33] magrittr_1.5 Formula_1.2-1 cluster_2.0.3 MASS_7.3-45 R6_2.1.0 rpart_4.1-10 nnet_7.3-11
As suggested in the comments by CL. and JasonAizkalns, a knitr bug is the issue, so downloading the developmental version of knitr should fix the issue.
update.packages(ask = FALSE, repos = 'http://cran.rstudio.org')
install.packages('knitr', repos = c('http://yihui.name/xran', 'http://cran.rstudio.org'))
OR
devtools::install_github('yihui/knitr', build_vignettes = TRUE)
Also for anyone else facing the same issue who is unable/unwilling to download the developmental version adding cat('\n\n') after the print command is a workaround for the bug!
i.e.
for(v in Values){
print(ggplot(mtcars, aes(x=carb, y = v, shape=gear)) + geom_point())
cat('\n\n')
}

DESeq2 - Invalid class “GRangesList” object

I've just updated my DESeq2 package from version 1.4.5 to version 1.6.3 and my scripts are no longer working. Specifically, I get the following error when generating a DESeqDataSet object with the function DESeqDataSetFromMatrix:
Error in validObject(.Object) :
invalid class “GRangesList” object: number of rows in DataTable 'mcols(x)' must match length of 'x'
To replicate this error one may either use the example shown in the DESeq2 vignette:
library("pasilla")
library("Biobase")
data("pasillaGenes")
countData <- counts(pasillaGenes)
colData <- pData(pasillaGenes)[,c("condition","type")]
dds <- DESeqDataSetFromMatrix(countData = countData,
colData = colData,
design = ~ condition)
or the example shown in the DESeq2 Reference Manual:
countData <- matrix(1:4,ncol=2)
colData <- data.frame(condition=factor(c("a","b")))
dds <- DESeqDataSetFromMatrix(countData, colData, formula(~ condition))
Thanks in advance for your help,
Alessia
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] parallel stats4 stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] DESeq2_1.6.3 RcppArmadillo_0.4.400.0 Rcpp_0.11.2
[4] GenomicRanges_1.16.4 GenomeInfoDb_1.0.2 IRanges_1.22.10
[7] S4Vectors_0.4.0 BiocGenerics_0.12.1 BiocInstaller_1.16.1
loaded via a namespace (and not attached):
[1] acepack_1.3-3.3 annotate_1.42.1 AnnotationDbi_1.26.0
[4] BatchJobs_1.3 BBmisc_1.7 Biobase_2.24.0
[7] BiocParallel_0.6.1 brew_1.0-6 checkmate_1.4
[10] cluster_1.15.3 codetools_0.2-9 colorspace_1.2-4
[13] DBI_0.3.0 digest_0.6.4 fail_1.2
[16] foreach_1.4.2 foreign_0.8-61 Formula_1.1-2
[19] genefilter_1.46.1 geneplotter_1.42.0 ggplot2_1.0.0
[22] grid_3.1.0 gtable_0.1.2 Hmisc_3.14-5
[25] iterators_1.0.7 lattice_0.20-29 latticeExtra_0.6-26
[28] locfit_1.5-9.1 MASS_7.3-34 munsell_0.4.2
[31] nnet_7.3-8 plyr_1.8.1 proto_0.3-10
[34] RColorBrewer_1.0-5 reshape2_1.4 rpart_4.1-8
[37] RSQLite_0.11.4 scales_0.2.4 sendmailR_1.1-2
[40] splines_3.1.0 stringr_0.6.2 survival_2.37-7
[43] tools_3.1.0 XML_3.98-1.1 xtable_1.7-4
[46] XVector_0.4.0
source("http://bioconductor.org/biocLite.R")
Bioconductor version 3.0 (BiocInstaller 1.16.1), ?biocLite for help

Resources