.swf created by knitr and hook_r2swf overlapping - r

I try to make a dynamic presentation with knitr and animation. I pick the hook_r2swf which is the only one works on my machine.
For example, I knit the following .Rmd files:
# Test Animation
```{r, fig.show='animate', aniopts='autoresume'}
opts_knit$set(animation.fun = hook_r2swf)
plot(1,1,type="n")
plot(2,2,type='n')
```
However, it seems that the .swf will overlap all figures plotted in the chunk which may look like this:
<p><embed width="504" height="504" name="plugin" src="https://dl.dropbox.com/u/11900271/unnamed-chunk-1.swf" type="application/x-shockwave-flash"></p>
Does anyone know how to make the result non-overlapping?
I am using ubuntu 12.04 with following session info:
R version 2.15.3 (2013-03-01)
Platform: i686-pc-linux-gnu (32-bit)
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=C LC_NAME=C LC_ADDRESS=C
[10] 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] testpkg_1.0 xts_0.9-1 zoo_1.7-9 Rcpp_0.10.2 roxygen2_2.2.2 digest_0.5.2
[7] knitr_1.1
loaded via a namespace (and not attached):
[1] brew_1.0-6 evaluate_0.4.3 formatR_0.6 grid_2.15.3 lattice_0.20-13 stringr_0.6.2
[7] tools_2.15.3
Thanks!

This seems to be an issue in the way animation is handled. The two plots are placed on top of each other. While I am not sure exactly how to prevent that itself, I can suggest the following workaround. By default, the background is transparent. If we change the background to white, the problem is solved:
```{r, fig.show='animate'}
opts_knit$set(animation.fun = hook_r2swf)
par(bg="white")
plot(1,1,type="n")
plot(2,2,type='n')
```

Related

Size of PDF files generated by knitr

I am using the following chunk in an Rnw file.
<<scatter,dev='pdf',include=TRUE>>=
a <- rnorm(1e4)
b <- rnorm(1e4)
plot(a,b)
#
I knitted the same Rnw file under R3.6.3 and R4.0.2, respectively. However, the PDF figure generated under R4.0.2 is much larger (~8 times) than the one from R3.6.3.
I am wondering if there is a way (eg. a chunk option) to reduce the PDF size under R4.0.2.
The session information of two different versions of R is shown below.
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)
Matrix products: default
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.29
loaded via a namespace (and not attached):
[1] compiler_4.0.2 magrittr_1.5 tools_4.0.2 stringi_1.4.6 highr_0.8 stringr_1.4.0
[7] xfun_0.16 evaluate_0.14
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)
Matrix products: default
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.28
loaded via a namespace (and not attached):
[1] compiler_3.6.3 magrittr_1.5 tools_3.6.3 stringi_1.4.6 highr_0.8 stringr_1.4.0
[7] xfun_0.12 evaluate_0.14
The only reference to pdf in the release notes lately has been in relation to the dingbats font. Looking at the reference, it says (emphasis mine):
useDingbats logical. Should small circles be rendered via the
Dingbats font? Defaults to TRUE, which produces smaller and better
output. Setting this to FALSE can work around font display problems in
broken PDF viewers: although this font is one of the 14 guaranteed to
be available in all PDF viewers, that guarantee is not always
honoured.
You can change the default via
pdf.options(useDingbats = TRUE)
in the first code chunk of your Rnw document. This change is global to your document. If you'd rather change it only for a specific code chunk, you may use the chunk option dev.args, e.g.,
<<scatter, dev='pdf', dev.args=list(useDingbats = TRUE)>>=
a <- rnorm(1e4)
b <- rnorm(1e4)
plot(a,b)
#

RODBC sqlFetch function crash

I'am trying to use package RODBCto access a mdb-file.
The mdb-file is created with ESRI GIS.
I want to change some entries in the attribute table.
If i try
sqlQuery(channnel = rddall, "SELECT* FROM abt_F;")
sqlFetch(channel=rddall,"txt_L ")
R crashes.
Screenshot
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=German_Austria.1252 LC_CTYPE=German_Austria.1252 LC_MONETARY=German_Austria.1252
[4] LC_NUMERIC=C LC_TIME=German_Austria.1252
attached base packages:
[1] splines grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] RODBC_1.3-12 brew_1.0-6 Hmisc_3.15-0 ggplot2_1.0.0 Formula_1.2-1 survival_2.37-7
[7] lattice_0.20-29 rgdal_1.1-8 sp_1.2-2
loaded via a namespace (and not attached):
[1] acepack_1.3-3.3 cluster_1.15.3 colorspace_1.2-5 digest_0.6.8 foreign_0.8-61
[6] gtable_0.1.2 latticeExtra_0.6-26 MASS_7.3-35 munsell_0.4.2 nnet_7.3-8
[11] plyr_1.8.3 proto_0.3-10 RColorBrewer_1.1-2 Rcpp_0.11.5 reshape2_1.4.1
[16] rpart_4.1-10 scales_0.2.4 stringr_0.6.2 tcltk_3.1.2 tools_3.1.2
Likely too late, but I just came across this question after encountering a similar problem. R was crashing for me when I tried to sqlFetch a table directly from my ArcGIS-created .mdb, and when I tried to fetch the table via a different non-GIS .mdb (I added the table to that database as an External Linked table, from the GIS .mdb). I finally got R to load the table correctly when I created a query in my non-GIS .mdb that basically replicated the initial table (although I dropped some of the unneeded columns in that query). Now, I just left the query as-is in my non-GIS .mdb, and sqlFetch the query, and it's working fine. Not really an R solution, but a potential workaround that may work for some folks.

ggdendrogram rotate with ggplot axis labels on right side for use in plotly

I am trying to generate a proper dendrogram in R with ggplot2 (more specifically ggdendro::ggdendrogram) because I would like to share it over plotly with my collaborators and currently I do not think it is possible with the api to generate a dendrogram with plotly.
I am mainly having troubles with the "axis" labeling when I rotate the dendrogram:
require(ggplot2)
require(ggdendro)
hc<-hclust(dist(iris[,1:4]),method="ward.D2")
ggd<-ggdendrogram(hc,rotate=TRUE)
ggd+scale_y_reverse()
This results in the following plot, where the tick labels are on the wrong side:
I would like to obtain a similar result as from R base graphics when executing plot(as.dendrogram(hc),horiz=TRUE)
As a bonus, I would like to be able to color the leaf (tick) labels separately as well as draw rect.hclust-like boxes, but this is not strictly necessary. I do know my way a little bit around ggplot2 syntax so no need to explain every possible solution in great length.
If relevant please find my sessionInfo() below, I am using R through Rstudio server on an Ubuntu 12.04 LTS server:
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C
[8] LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggdendro_0.1-14 cluster_1.15.2 plotly_0.4 RJSONIO_1.2-0.2 RCurl_1.95-4.1 bitops_1.0-6 devtools_1.5
[8] extrafont_0.16 RColorBrewer_1.0-5 scales_0.2.4 vegan_2.0-10 lattice_0.20-29 permute_0.8-3 splitstackshape_1.2.0
[15] data.table_1.9.2 BurStMisc_1.00 reshape2_1.4 xlsx_0.5.5 xlsxjars_0.6.0 rJava_0.9-6 ggplot2_0.9.3.1
[22] plyr_1.8.1
loaded via a namespace (and not attached):
[1] MASS_7.3-32 Rcpp_0.11.1 Rttf2pt1_1.3 colorspace_1.2-4 digest_0.6.4 evaluate_0.5.5 extrafontdb_1.0 formatR_0.10 grid_3.1.0
[10] gtable_0.1.2 httr_0.3 knitr_1.6 labeling_0.2 memoise_0.2.1 munsell_0.4.2 parallel_3.1.0 proto_0.3-10 stringr_0.6.2
[19] tools_3.1.0 whisker_0.3-2

R - XCMS package Error

I' ve the following problem :
Error in .C("NetCDFOpen", as.character(filename), ncid = integer(1), status = integer(1), :
C symbol name "NetCDFOpen" not in DLL for package "xcms"
How do you get this error :
nc <- xcms:::netCDFOpen(cdfFile)
ncData <- xcms:::netCDFRawData(nc)
xcms:::netCDFClose(nc)
I don't know why this don't works, although it should. For further info feel free to ask. Free .cdf files canf be found in the TargetSearchData package.
Code example :
## The directory with the NetCDF GC-MS files
cdfpath <- file.path(.find.package("TargetSearchData"), "gc-ms-data")
cdfpath
I don't think that it should, as you are implying. First, you are using a non-exported function through the :::. In addition, as stated by the error message, the is no NetCDFOpen symbol defined is the dll/so files.
Using the standard input functionality from xcms, works smoothly:
> library("xcms")
> cdfpath <- file.path(.find.package("TargetSearchData"), "gc-ms-data")
> cdfFile <- dir(cdfpath, full.names=TRUE)[1]
> xs <- xcmsSet(cdfFile)
7235eg04: 135:168 185:314 235:444 285:580
> xr <- xcmsRaw(cdfFile)
If you really want to input your data manually, you should use the functionality from the mzR package, which xcms depends on:
> openMSfile(cdfFile)
Mass Spectrometry file handle.
Filename: /home/lgatto/R/x86_64-unknown-linux-gnu-library/2.16/TargetSearchData/gc-ms-data/7235eg04.cdf
Number of scans: 4400
Finally, do pay attention to always provide the output of sessionInfo, to assure that you are using the latest version. In my case:
> sessionInfo()
R Under development (unstable) (2012-10-23 r61007)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] BiocInstaller_1.9.4 xcms_1.35.1 mzR_1.5.1
[4] Rcpp_0.9.15
loaded via a namespace (and not attached):
[1] Biobase_2.19.0 BiocGenerics_0.5.1 codetools_0.2-8 parallel_2.16.0
[5] tools_2.16.0
although if might be different for you, if you use the stable version of R and Bioconductor (currently 2.15.2/2.11).
Hope this helps.

Help with x11 and dev.off

Why does this code throw warnings & how should I rewrite it?
x11(width = 8, height = 8)
plot(1:10)
points(1, 5, col='red')
dev.off() # Throws "Warning message: In dev.off() : Display list redraw incomplete"
The error disappears if I remove the x11() line. Thank you in advance,
Adrian
I can reproduce this bug, but only if I'm trying to source the code. I get two empty plot windows. You may have noticed that at first there's 8x8 X11 window, but then it's closed, and you end up with two default-sized windows (7x7), with the one in the front marked as ACTIVE. However, if you omit width and height parameters, everything works OK. This looks like X11 issue to me, and, frankly, I have no bloody idea what causes it, but it definitely has something to do with device geometry. If I set X11.options(width = 8, height = 8) and source the script, I get the same bug again.
Long story short, I can replicate the bug, but I have no idea what's causing it. Anyway, this yields no errors:
x11()
plot(1:10)
points(1, 5, col='red')
dev.off()
EDIT
I'm using Arch Linux FWIW, here's my sessionInfo():
R version 2.12.2 (2011-02-25)
Platform: i686-pc-linux-gnu (32-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=C 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

Resources