error with function regmatches using R - r

I'm trying to use the function regmatches, in R, but i'm getting an error (R says it can't find the function).
I'm quite tired now and maybe I'm doing some really silly mistake. However, I don't know what's wrong.
I tried to use ??regmatches, but it didn't find anything.
Next I tried the "sos" package and function findFn("regmatches"), but it returned:
found 0 matches
x has zero rows; nothing to display.
Mensagens de aviso perdidas:
In findFn("regmatches") : HIT not found in HTML; processing one page only.
I don't know what else to do.
I know I may be doing a silly mistake like this one, but I don't know what else to do. Below is my session info:
R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
1 LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Brazil.1252
attached base packages:
1 stats graphics grDevices utils datasets methods base
other attached packages:
1 sos_1.3-1 brew_1.0-6
loaded via a namespace (and not attached):
1 tools_2.12.2

regmatches was added in R 2.14.0...

I'm sorry guys. It happens that is was a silly mistake. After almost giving up, I decided to check if it was a problem with my version of R. So, I took a look at the CRAN webpage and found this under what's new with R 2.14.
New function regmatches() for extracting or replacing matched or non-matched substrings from match data obtained by regexpr(), gregexpr() and regexec().
So, It's time to update R. I thought that using version 2.12.2 wasn't that bad, but it happens it was.

Related

How can I knit a .Rnw-file into latex, with plots as tikzpicture environments? (error: formal argument matched by multiple actual arguments)

I'm trying to convert a .Rnw document to latex (to be included in another .tex-document). All plots are generated using the tikz device, but each of them as a standalone document. My goal is to have them in tikzpicture environments.
Solution attempt
According to the knitr documentation on plots, it should be possible to pass standAlone=FALSE via the dev.args-list. This produces the error message formal argument "standAlone" matched by multiple actual arguments. Knitr issue #514 describes the same error message, but their solution doesn't work here.
To reproduce, run knitr::knit("mwe.Rnw") on the following file:
\section*{MWE}
<<echo=FALSE,dev="tikz",dev.args=list(standAlone=FALSE)>>=
plot(x=1:10)
#
Error message:
Quitting from lines 3-4 (mwe.Rnw)
Error in tikzDevice::tikz(..., packages = c("\n\\nonstopmode\n", packages, :
formal argument "standAlone" matched by multiple actual arguments
According to tikzDevice documentation, standAlone=FALSE should be the default anyway, no idea why this doesn't apply here.
Any help is greatly appreciated. A seemingly related, but less specific, question has been posted but without answer.
Setup
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.2
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
knitr_1.27
tikzDevice_0.12.3
The argument standAlone is controlled by the chunk option external, so what you need is:
<<dev="tikz", external=FALSE>>=

R and RStudio don't display greek letters and other symbols - display squares instead

I can't seem to display greek letters in r. I'm working with RStudio, and I can't seem to display greek characters no matter what I try. Initially I tried to display greek letters inside bquote, using syntax from a class I took, which the prof. published and demonstrated it worked in class. When all it showed was squares**, I tried more basic ways of displaying greek letters. I tried to use expression and than I tried to find the simplest way and ran this syntax which I found online:
mycoef <- rnorm (1000)
hist(mycoef, main = expression(beta))
In all cases it either display a square (like an unrecognized symbol), or just the word (beta, chi, etc.,). This syntax also displayed a square using R instead of RStudio.
I tried to change a bit the encoding of the file (ASCII/UTF-8), but this didn't change anything. I am working on a mac (macOS Sierra 10.12.4) if that changes anything.
**when using the bquote syntax, greek letters were not the only characters it changed to squares. Also == and ~~ without quotes were displayed as squares.
This is my sessionInfo() -
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] pt_PT.ISO8859-1/pt_PT.ISO8859-1/pt_PT.ISO8859-1/C/pt_PT.ISO8859-1/C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] plyr_1.8.4 meta_4.8-4 openxlsx_4.0.17
loaded via a namespace (and not attached):
[1] compiler_3.4.2 tools_3.4.2 Rcpp_0.12.13
=====
Note that as a try to fix this problem I ran this syntax that is displayed in the sessionInfo - Sys.setlocale("LC_ALL", "pt_PT.ISO8859-1"), which didn't help.
Thanks!
You can try using package latex2exp if you know the basics of LaTeX:
library(latex2exp)
mycoef <- rnorm (1000)
hist(mycoef, main = TeX("$\\beta$"))
I solved this problem updating the Symbols Font on Windows. (1) Download the file Symbol.ttf (https://www.fontsupply.com/fonts/S/Symbol.html),
(2) Find the file symbol.ttf in your \Windows\Fonts folder, and replace with the fresh copy.

Substitute not displaying text on plots

I just recently learnt about plotmath and its ability to put mathematical expression in text on plots.
However I'm encountering some strange behaviour where the substitute function does not render any text.
Here's a simple case that should work (from this answer):
labNames <- c('xLab','yLab')
plot(c(1:10),
xlab=substitute(paste(nn, x^2), list(nn=labNames[1])),
ylab=substitute(paste(nn, y^2), list(nn=labNames[2])))
When I run this code snippet, there is no xlab or ylab text.
I'm running mac osx and R 3.0.0. This problem persists whether i output to Quartz or to a png file.
Here's my sessionInfo():
R version 3.0.0 (2013-04-03)
Platform: x86_64-apple-darwin12.3.0 (64-bit)
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
I found the culprit: there was a weird interaction with an option in my .Rprofile
The following line causes the issue if i don't load the devtools package:
options(devtools.desc.author="'Scott Ritchie <sritchie73#gmail.com> [aut, cre]'")
Strangely, there doesn't seem to be an issue if i define other irrelevant options (options(notanoption=TRUE) caused no issues).

ggplot2 ggsave function causes graphics device to not display plots

I've updated my ggplot2 library and I am now having a problem where after calling ggsave, the graphics device no longer displays the plot. I'm unable to resolve the issue meaning I cannot export the plots as needed. Please help.
Searching the web has revealed some mention of problems with dpi mismatches, but setting or changing the dpi appears to have no effect. This problem appears to have begun after doing an update of the ggplot2 library.
The following code reproduces the problem:
library(ggplot2);
df <- read.table(textConnection('value,value1
1,1
2,2
3,3 '),header=TRUE,sep=',');
ggplot(df,aes(x=value,y=value1)) + geom_point();
setwd('c:/temp');
ggsave('test.png');
After running, the output is blank, and the graphics device no longer displays the plot. Any subsequent plots are not displayed on the graphics device.
After running dev.off(), new plots are displayed okay, until ggsave is called again.
sessionInfo() reports the versions of R and libraries as:
R version 3.0.0 (2013-04-03)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_New Zealand.1252 LC_CTYPE=English_New Zealand.1252
[3] LC_MONETARY=English_New Zealand.1252 LC_NUMERIC=C
[5] LC_TIME=English_New Zealand.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plyr_1.8 ggplot2_0.9.3.1 RODBC_1.3-6
loaded via a namespace (and not attached):
[1] colorspace_1.2-2 dichromat_2.0-0 digest_0.6.3 grid_3.0.0 gtable_0.1.2
[6] labeling_0.1 MASS_7.3-26 munsell_0.4 proto_0.3-10 RColorBrewer_1.0-5
[11] reshape2_1.2.2 scales_0.2.3 stringr_0.6.2 tools_3.0.0
The problem occurs in 2.15.0 and 2.15.3 of R also.
EDIT: changed code so data would load using sep=',' rather than whitespace
ADDITION: further testing reveals that this may in fact be a bug with RStudio and how it is displaying the graphics device after ggsave, rather than R itself. Running the above script in RGui does not reproduce the problem, only in RStudio V0.97.336 + V0.97.449.
Seems to be an issue with RStudio. The issue is described here and here.
The workaround is to install RStudio V0.97.311, or ensure that you execute the ggplot and ggsave lines separately (i.e. don't select and run together in a block with control+enter).

Mathematical notion/superscripts in Rd files

I'm working on filling in an Rd file for a function.
When I use \eqn{2^{x}} in the Details section, then build and install the package, there is no superscripted exponent.
Looking at R-exts.pdf, it points to Poisson.Rd as an example on how to use \eqn or \deqn. In the example in that file, there is a superscripted exponent.
When I look at the help file for Poisson (?Poisson), There are no superscripted exponents.
Is this an issue on my computer or is this standard behavior?
Thanks!
> sessionInfo()
R version 2.11.1 (2010-05-31)
i386-apple-darwin9.8.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] cimis_0.1-3 RLastFM_0.1-4 RCurl_1.4-2 bitops_1.0-4.1 XML_3.1-0 lattice_0.18-8
loaded via a namespace (and not attached):
[1] grid_2.11.1 tools_2.11.1
Nowadays, people mainly use the HTML help.
To get the superscript in the HTML help as well as in the PDF help, do:
\ifelse{html}{\out{2<sup>x</sup>}}{\eqn{2^x}}
The syntax is:
\ifelse{html}{\out{HTML CODE}}{\eqn{LATEX-LIKE CODE}{ASCII}}
with {ASCII} optional.
You don't say where you looked to see if there was a superscripted exponent. I presume the text based help, not the PDF version of the manual?
The syntax for the \eqn macro is \eqn{latex}{ascii}. The {ascii} bit is optional, in which case R will do it's best to render the LaTeX version. Conventionally, subscripts in ASCII would be wrapped in [] and superscipts with ^.
So I would write:
\eqn{2^{x}}{2^x}
But in all practical senses these are the same. The issue is just that the text help can't display superscipts, but the PDF can.

Resources