RMarkdown: preserve source code formatting in code cell - r

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.

Related

Issue with doparallel and foreach on centos cluster

I am trying to use foreach and doParallel to optimize the computation of some image processing. I have ParamIter which is the parameter to iterate over. ImageProcessing is my custom function to process the images and save the data that has been processed.
library(methods)
library(fftwtools)
library(EBImage)
library(tidyverse)
library(foreach)
library(doParallel)
registerDoParallel(20)
foreach(ParamIter = unique(AllImages$ParamIter)) %dopar% {
AllImagesTemp = AllImages[AllImages$ParamIter == ParamIter,]
ImageProcessing(Image = AllImagesTemp,
Plate = unique(AllImagesTemp$Plate),
TimePoint = unique(AllImagesTemp$TimePoint),
Marker = unique(AllImagesTemp$Marker),
Replicate = unique(AllImagesTemp$Replicate),
Well = unique(AllImagesTemp$ID),
Position = unique(AllImagesTemp$Position),
SaveDir = WellDir,
SaveParam = ParamIter,
ThrEmptyImage = .04)
}
Everything works perfectly locally on a machine with Ubuntu 18.04 and a session as per below:
> sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=de_DE.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=de_DE.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=de_DE.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2.2 fftwtools_0.9-8 doParallel_1.0.14 iterators_1.0.10 foreach_1.4.4 forcats_0.3.0 stringr_1.4.0 dplyr_0.7.7
[9] purrr_0.3.1 readr_1.1.1 tidyr_0.8.2 tibble_2.0.1 ggplot2_3.1.0 tidyverse_1.2.1 EBImage_4.24.0
loaded via a namespace (and not attached):
[1] tidyselect_0.2.5 locfit_1.5-9.1 haven_1.1.2 lattice_0.20-38 colorspace_1.4-0 htmltools_0.3.6 yaml_2.2.0
[8] rlang_0.3.1 pillar_1.3.1 withr_2.1.2 glue_1.3.0 BiocGenerics_0.28.0 modelr_0.1.2 readxl_1.1.0
[15] jpeg_0.1-8 bindr_0.1.1 plyr_1.8.4 munsell_0.5.0 gtable_0.2.0 cellranger_1.1.0 rvest_0.3.2
[22] htmlwidgets_1.3 codetools_0.2-16 broom_0.5.0 Rcpp_1.0.0 backports_1.1.3 scales_1.0.0 jsonlite_1.6
[29] abind_1.4-5 hms_0.4.2 png_0.1-7 digest_0.6.18 stringi_1.3.1 tiff_0.1-5 grid_3.5.3
[36] cli_1.0.1 tools_3.5.3 bitops_1.0-6 magrittr_1.5 RCurl_1.95-4.11 lazyeval_0.2.1 crayon_1.3.4
[43] pkgconfig_2.0.2 xml2_1.2.0 lubridate_1.7.4 assertthat_0.2.0 httr_1.4.0 rstudioapi_0.9.0 R6_2.3.0
[50] nlme_3.1-137 compiler_3.5.3
However if I am trying to do this on my local cluster it doesn't work and provides me with this error:
Error in { :
task 1 failed - "a call to callNextMethod() appears in a call to ‘.Method’, but the call does not seem to come from either a generic function or another 'callNextMethod'"
Calls: %dopar% -> <Anonymous>
Execution halted
My session on the centos cluster looks like:
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS: /cm/shared/apps/R/64/3.4.1/lib64/R/lib/libRblas.so
LAPACK: /cm/shared/apps/R/64/3.4.1/lib64/R/lib/libRlapack.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] parallel stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] doParallel_1.0.14 iterators_1.0.10 foreach_1.4.4 forcats_0.3.0
[5] stringr_1.3.1 dplyr_0.7.8 purrr_0.3.0 readr_1.3.1
[9] tidyr_0.8.2 tibble_2.0.1 ggplot2_3.1.0 tidyverse_1.2.1
[13] EBImage_4.20.1 fftwtools_0.9-8
loaded via a namespace (and not attached):
[1] tidyselect_0.2.5 locfit_1.5-9.1 haven_2.0.0
[4] lattice_0.20-35 colorspace_1.4-0 generics_0.0.2
[7] htmltools_0.3.6 rlang_0.3.1 pillar_1.3.1
[10] withr_2.1.2 glue_1.3.0 BiocGenerics_0.24.0
[13] modelr_0.1.2 readxl_1.2.0 bindrcpp_0.2.2
[16] jpeg_0.1-8 bindr_0.1.1 plyr_1.8.4
[19] munsell_0.5.0 gtable_0.2.0 cellranger_1.1.0
[22] rvest_0.3.2 htmlwidgets_1.3 codetools_0.2-15
[25] broom_0.5.1 Rcpp_1.0.0 scales_1.0.0
[28] backports_1.1.3 jsonlite_1.6 abind_1.4-5
[31] hms_0.4.2 png_0.1-7 digest_0.6.18
[34] stringi_1.2.4 tiff_0.1-5 grid_3.4.1
[37] cli_1.0.1 bitops_1.0-6 tools_3.4.1
[40] magrittr_1.5 RCurl_1.95-4.10 lazyeval_0.2.1
[43] crayon_1.3.4 pkgconfig_2.0.2 xml2_1.2.0
[46] lubridate_1.7.4 assertthat_0.2.0 httr_1.4.0
[49] rstudioapi_0.9.0 R6_2.3.0 nlme_3.1-131
[52] compiler_3.4.1
I do not understand the error and what it is pointing me towards. Does someone have an idea of how I could solve this problem?
Upgrading to a newer version of R is not a possibility on my local cluster.
Cheers,
Mathieu

ggplot call changes locale LC_NUMERIC variable

I am struggling with a strange behaviour of R/ggplot.
Starting a fresh R session and calling sessionInfo() gives
R version 3.5.1 (2018-07-02) Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 19
Matrix products: default BLAS:
/home/nicolai/anaconda3/lib/R/lib/libRblas.so LAPACK:
/home/nicolai/anaconda3/lib/R/lib/libRlapack.so
locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
LC_MONETARY=de_DE.UTF-8 [6] LC_MESSAGES=en_US.UTF-8
LC_PAPER=de_DE.UTF-8 LC_NAME=C LC_ADDRESS=C
LC_TELEPHONE=C [11] LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=C
attached base packages: [1] stats graphics grDevices utils
datasets methods base
other attached packages: [1] RevoUtils_11.0.1 RevoUtilsMath_11.0.0
loaded via a namespace (and not attached): [1] Rcpp_0.12.18
assertthat_0.2.0 dplyr_0.7.6 crayon_1.3.4 R6_2.2.2
grid_3.5.1 plyr_1.8.4 gtable_0.2.0 [9] magrittr_1.5
scales_0.5.0 ggplot2_3.0.0 pillar_1.3.0 rlang_0.2.1
lazyeval_0.2.1 rstudioapi_0.7 bindrcpp_0.2.2 [17] tools_3.5.1
glue_1.3.0 purrr_0.2.5 munsell_0.5.0 yaml_2.2.0
compiler_3.5.1 pkgconfig_2.0.1 colorspace_1.3-2 [25]
tidyselect_0.2.4 bindr_0.1.1 tibble_1.4.2
Notice how LC_NUMERIC is set to C.
Typing 1.2 returns
1.2
After calling the following two lines of code
library(ggplot2)
ggplot(data.frame(a=1:5, b=1:5), aes(a, b)) + geom_point()
My R-session mysteriously changes the decimal separator from a dot to a comma. Typing 1.2 returns
1,2
All plots I generate have the comma as the decimal separator. Calling sessionInfo() returns
R version 3.5.1 (2018-07-02) Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 19
Matrix products: default BLAS:
/home/nicolai/anaconda3/lib/R/lib/libRblas.so LAPACK:
/home/nicolai/anaconda3/lib/R/lib/libRlapack.so
locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=de_DE.UTF-8
LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5]
LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8
LC_PAPER=de_DE.UTF-8 LC_NAME=de_DE.UTF-8 [9]
LC_ADDRESS=de_DE.UTF-8 LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=de_DE.UTF-8
attached base packages: [1] stats graphics grDevices utils
datasets methods base
other attached packages: [1] ggplot2_3.0.0 RevoUtils_11.0.1
RevoUtilsMath_11.0.0
loaded via a namespace (and not attached): [1] Rcpp_0.12.18
rstudioapi_0.7 bindr_0.1.1 magrittr_1.5 tidyselect_0.2.4
munsell_0.5.0 colorspace_1.3-2 R6_2.2.2 [9] rlang_0.2.1
plyr_1.8.4 dplyr_0.7.6 tools_3.5.1 grid_3.5.1
gtable_0.2.0 withr_2.1.2 yaml_2.2.0 [17] lazyeval_0.2.1
assertthat_0.2.0 tibble_1.4.2 crayon_1.3.4 bindrcpp_0.2.2
purrr_0.2.5 glue_1.3.0 labeling_0.3 [25] compiler_3.5.1
pillar_1.3.0 scales_0.5.0 pkgconfig_2.0.1
Notice how the LC_NUMERIC value has changed. I assume this causes the change in the decimal separator, but I have no idea how that makes sense.
This is something that happened after installing a fresh Mint version together with a fresh, up-to-date R version.
Does someone have an idea of what could cause this?

R Datatable Styling one Column Based on Another Column and Hiding Column Does Not Work after Running Shiny App

I'm trying to follow the example on the R DT website to style one column based on another column and hide the column that I use for styling but the column was not hidden (it works fine if I run it in a new R session but does not work if I run it after I run my Shiny app). My code is as follow:
library(DT)
df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10),
sample(0:1, 10, TRUE)))
datatable(df, options = list(columnDefs = list(list(targets = 6,
visible = FALSE)))) %>%
formatStyle('V1', 'V6', backgroundColor = styleEqual(c(0, 1),
c('gray', 'yellow')))
Column V6 is supposed to be hidden but as you can see from this picture, it is still visible:
Session info is as follow:
R version 3.4.0 (2017-04-21)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server 7.4 (Maipo)
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C 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] bindrcpp_0.2.2 webshot_0.4.1 stringr_1.3.1 shinythemes_1.1.1 shinyjs_1.0 plotly_4.7.1 ggplot2_3.0.0.9000 lubridate_1.7.4
[9] DT_0.4.17 dplyr_0.7.6 data.table_1.11.4 AGD_0.39 shiny_1.1.0
loaded via a namespace (and not attached):
[1] tidyselect_0.2.4 reshape2_1.4.3 purrr_0.2.2.2 splines_3.4.0 lattice_0.20-35 colorspace_1.3-2 htmltools_0.3.6 viridisLite_0.3.0
[9] yaml_2.1.19 survival_2.41-3 rlang_0.2.1 later_0.7.3 pillar_1.3.0 glue_1.3.0 withr_2.1.2 RColorBrewer_1.1-2
[17] bindr_0.1.1 plyr_1.8.4 munsell_0.5.0 gtable_0.2.0 devtools_1.13.3 htmlwidgets_1.2.1 memoise_1.1.0 gamlss.dist_5.0-2
[25] crosstalk_1.0.0 httpuv_1.4.4.1 gamlss_5.0-2 gamlss.data_5.0-0 curl_2.8.1 parallel_3.4.0 Rcpp_0.12.17 xtable_1.8-2
[33] promises_1.0.1 scales_0.5.0 jsonlite_1.5 mime_0.5 digest_0.6.15 stringi_1.2.3 grid_3.4.0 tools_3.4.0
[41] magrittr_1.5 lazyeval_0.2.1 tibble_1.4.2 crayon_1.3.4 tidyr_0.6.3 pkgconfig_2.0.1 MASS_7.3-47 Matrix_1.2-9
[49] assertthat_0.2.0 httr_1.2.1 rstudioapi_0.6 R6_2.2.2 git2r_0.19.0 nlme_3.1-131 compiler_3.4.0
Anyone has any idea why it's not working as expected?

ggparagraph is not displayed

I have problem with the function ggparagraph() from ggpubr package. Its content is not drawing. If I use the function:
example(ggparagraph)
The plot is drawing without any problem, but the "ggparagraph area" (below plot) is empty. The same problem is if I use custom scripts, where the ggparagraph is applied.
R does not print any error message. Where can be the problem?
My session info is:
sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 15063)
Matrix products: default
locale:
1 LC_COLLATE=Slovak_Slovakia.1250 LC_CTYPE=Slovak_Slovakia.1250
[3] LC_MONETARY=Slovak_Slovakia.1250 LC_NUMERIC=C
[5] LC_TIME=Slovak_Slovakia.1250
attached base packages:
1 stats graphics grDevices utils datasets methods base
other attached packages:
1 ggpubr_0.1.4 magrittr_1.5 gridExtra_2.2.1 dplyr_0.7.2
[5] purrr_0.2.3 readr_1.1.1 tidyr_0.6.3 tibble_1.3.3
[9] ggplot2_2.2.1 tidyverse_1.1.1
loaded via a namespace (and not attached):
1 Rcpp_0.12.12 cellranger_1.1.0 compiler_3.4.1 plyr_1.8.4
[5] bindr_0.1 forcats_0.2.0 tools_3.4.1 jsonlite_1.5
[9] lubridate_1.6.0 nlme_3.1-131 gtable_0.2.0 lattice_0.20-35
[13] pkgconfig_2.0.1 rlang_0.1.2 psych_1.7.5 parallel_3.4.1
[17] haven_1.1.0 bindrcpp_0.2 xml2_1.1.1 stringr_1.2.0
[21] httr_1.2.1 hms_0.3 cowplot_0.8.0 grid_3.4.1
[25] glue_1.1.1 R6_2.2.2 readxl_1.0.0 foreign_0.8-69
[29] reshape2_1.4.2 modelr_0.1.1 scales_0.4.1 rvest_0.3.2
[33] assertthat_0.2.0 mnormt_1.5-5 colorspace_1.3-2 labeling_0.3
[37] stringi_1.1.5 lazyeval_0.2.0 munsell_0.4.3 broom_0.4.2
Finally, I don't find where is the problem, but if I install this package from github (instead of CRAN), all paragraphs are rendered correctly.

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

Resources