dplyr print to console is offset - r

library(nycflights13)
# print head to console
flights
This is what I see:
This what should happen:
Is this an R, RStudio, dplyr or some options issue?
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin15.0.0 (64-bit)
Running under: OS X 10.11 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
other attached packages:
[1] nycflights13_0.1 dplyr_0.4.3

The issue does not originate in your code but is a minor issue/bug in RStudio, which shows the data as if you decreased the width of the console after printing the values by hand. What you can do is increase the width of the console in RStudio by hand again.
However, I have no idea what causes the error or how to resolve it in a nicer way without adjusting it by hand. The error sometimes shows up when printing a large amounts of ordered data (data.frame, data.table, tbl_df etc.) as if RStudio sets the boundaries for printing too tight.

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.

How to find words by Ctrl + F on R data sets WIndow or R console?

I wanted to see all the data sets in all the available packages in R, for which the command I used was
data(package = .packages(all.available = TRUE))
This results in an R window called R data sets window like below showing 100s of data sets listed package wise.
Now if I want to find something based on words in the above Window, Example say word cancer in that window, I am not able to use ctrl+f on it. How can I use ctrl+f or any other find method in any of the R Windows that pops up. Even in console we can not use searching.
Of course we can copy paste text and search. I want to know if we can do it in R itself.
I can perform ctrl+f only on R Script Window and not any other Window.
Session Information:
sessionInfo()
# R version 3.3.1 (2016-06-21)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 14393)
Any help on this is highly appreciated.

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).

axis labels are not plotted in English

R doesn't plot automatically the axis labels in English (for example Months are in French).
I use (if the information is useful...):
windows (and I have already changed "language = en" in .../Programs/R/etc/Rconsole to make R speaking English)
RStudio
ggplot2
I know that I am not the only one with this issue but I never found a solution.
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252 LC_NUMERIC=C LC_TIME=French_France.1252
To change language of the environment use the following command:
Sys.setenv("LANGUAGE"="En")
To change locale to English:
Sys.setlocale("LC_ALL", "English")
The name of the locale depends on what is installed on your system (for example, you might use "en_GB.UTF-8" instead of "English").
The locale you see in sessionInfo() is system wide specific, go to windows regional options and change from french to english then restart R and you should see English instead of french...but this is only if you want do it quick and dirty, it will then be applied system wide. Else ?locale should explain and to do it more surgically

Resources