Default language of R - r

I have the R software installed on my MacBook, but the problem is that the default language is set on "russian", I really don't know why. When I call R from my terminal I see the message below
Giulios-MBP:~ opisthofulax$ R
R version 3.2.4 (2016-03-10) -- "Very Secure Dishes"
Copyright (C) 2016 The R Foundation for Statistical Computing
R version 3.2.4 (2016-03-10) -- "Very Secure Dishes"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)
R -- это свободное ПО, и оно поставляется безо всяких гарантий.
Вы вольны распространять его при соблюдении некоторых условий.
Введите 'license()' для получения более подробной информации.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Введите 'demo()' для запуска демонстрационных программ, 'help()' -- для
получения справки, 'help.start()' -- для доступа к справке через браузер.
Введите 'q()', чтобы выйти из R.
>
As you can notice the software is half in russian half in english, and, obviously, I would like to change the default language to ENG.
I've found a temporary solution here on StackOverflow
but it doesn't solve my problem, because every time I call R from my terminal it's again in RUS.
I was wondering if there's a definitive solution/command to change and set the default language to ENG. Thanks all.
=
I didn't get the problem solved, since, even if I took a look here, on the other SO link.
I wasn't able to locate the file Rconsole, which seems to be the key to change the language.
I looked for it on my MacBook (and maybe the problem is because of the new Sierra OS) with the search tool, but the file seems not to be on my computer.
So the problem is actually still there. Any suggestion?

There are several questions dealing with that problem:
- How to change language settings in R
- The R console is in my native language, how can I set R to English?
Type locale in the terminal and check your language settings. If you want everything to be in US english, it should look like this
locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
In your case, I assume that it is a mix of en_US.UTF-8 and your local russian language setting.
These variables are set system wide by your language & region settings. However, you can also set them in your ~/.bash_profile. For example, I use the following settings:
# language settings
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
Restart R/RStudio and everything should work.

Also, this worked for me, OS X Big Sur with R console from Anaconda.
which R showed /opt/anaconda3/envs/rm_resolutions/lib/R/bin/R
Good, it's using Anaconda
(rm_resolutions is my active virtual environment)
cd /opt/anaconda3/envs/rm_resolutions/lib/R/etc
Do at least one of these:
Add LANGUAGE=en to the Renviron file there.
Create Rconsole with language = en
For example, echo language = en > Rconsole
I did both of step 3, not sure which is used / preferred.
I also have the R.app installed, which is totally separate.

Related

Peculiar Behavior After Reboot and Clearing Workspace Possibly Related to R and RStudio Updates

I recently upgraded to R version 4.0.2 and RStudio 1.3.1056 and believe that may be at the root of this problem. After copying a section of my Shiny code to create a minimal reproducible example (mprex), I get an error for a section of code that's not in the mprex. I cleared my RStudio workspace and rebooted both my computer and RStudio, but continue to get the same error.
Here's my code:
library(shiny)
# Define UI
ui <- (fluidPage
(
fileInput("sessionFileName", "Session File Name")
)
)
# Define server logic
server <- (function(input, output, session)
{
inputParameters <- reactive ({
if (is.null(input$sessionFileName)) return
inFile <- input$sessionFileName
if (!is.null(inFile)) {
inputData <- readRDS(file=inFile$name)
}
inputIDs <- names(inputData)
inputvalues <- unlist(inputData)
for (i in 1:length(inputData)) {
print (paste(inputIDs[i],inputvalues[[i]],sep=' '))
session$sendInputMessage(inputIDs[i], list(value=inputvalues[[i]]) )
}
})
})
# Start the shiny app
shinyApp(ui = ui, server = server)
And here's the error I get when I try to run my code:
Error in reqHistoricalData(tws, twsEquity(equity), yesterday4PM, backtestFrequency, :
could not find function "reqHistoricalData"
It's pretty clear the error has nothing to do with the code I'm trying to run. I realize my code may have other errors. The error appears when I launch my code. My guess is that someone running this code on a different machine would not get the same error, but I don't know yet if that's true.
Here's the startup banner when I start an RStudio session.
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[Workspace loaded from ~/Library/MobileDocuments/com~apple~CloudDocs/r Dev/.RData]
For this last line of the startup banner, "[Workspace loaded from ~...]", I don't understand if there's a way for me to delete and/or reset the workspace that's being loaded. Perhaps that's the solution to this problem.
I do have many packages in my environment, including IBrokers, to which this error refers. I've been running other Shiny scripts that access the function reqHistoricalData().
Is this a bug in either Shiny and/or R? Any ideas about how to get this code to run?

Warning: GNU Extension

When I submit my package to CRAN, it does not pass the automatic incoming checks with a following warning:
* checking whether package 'EpiILM' can be installed ... WARNING
Found the following significant warnings:
Warning: GNU Extension: Different type kinds at (1)
and corresponding log file says
Epimcmc.f95:440.25:
psi= min(1.0,exp(ratio))
1
Warning: GNU Extension: Different type kinds at (1)
When I tested my package using R CMD CHECK and R CMD CHECK --as-cran, both result no warnings or notes. I am using an R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch" on my MacOS and codes are written in Fortran 95.
Any suggestions?
Your code is too short to diagnose exactly, but it can be probably inferred safely what the not-shown part of the code is.
Your ratio is of different kind than default one, probably `double precision.
But 1.0 is the default kind (aka. single precision).
Mixing different kinds in min() is not allowed in Fortran, but you do this in:
min(1.0,exp(ratio))
To fix the problem, use literals of the same kind as ratio is. So if it is a double precision, you can use:
min(1.0d0, exp(ratio))
and if it is some real(rk) you can use
min(1.0_rk, exp(ratio))
The real(.., kind=rk) function can also be used.
The warning says that the GNU Fortran compiler recognizes it is not allowed in Fortran, but allows it as a non-standard extension. Whether using this extension is allowed by the CRAN coding standards is a different question. Probably no, if it got rejected.

Commandline Arguments in R are null

I'm coding in R.
I thought I was making pretty good progress in R. I had created a script that read the command line arguments (there was 1 single argument, it was the name of a data file), read in data from a .csv, performed a regression and printed some data.
Somewhere along the way, I modified something and everything went out the window. Subsequently, I have torn down my entire script and I now have the most basic script and it is behaving strangely. Here is what I've got now:
#NOTE: To run the script use the following command in terminal R CMD
#BATCH scriptname arguments #store the current directory
initial.dir<-getwd()
#set the output
sink("PROGOUT.out")
#Get commandline arguments
args<-commandArgs(trailingOnly=TRUE)
print(args)
"HELLO WORLD"
I expected this program to create a file, PROGOUT.out, that contains the commandline arguments and the phrase HELLO WORLD.
At the command prompt I ran,
$ R CMD BATCH R_ScriptV3.R test1 test2 test3 test4
The program creates two files, 'test1' and 'PROGOUT.out'
This is the contents of PROGOUT.out:
character(0)
[1] "HELLO WORLD"
proc.time() user system elapsed 0.201 0.026 0.219
This is the contents of test1:
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" Copyright (C) 2014 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin10.8.0 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] >
NOTE: To run the script use the following command in terminal
R CMD BATCH scriptname arguments > > #store the current directory
initial.dir<-getwd()
set the output
sink("PROGOUT.out")
Get commandline arguments
args<-commandArgs(trailingOnly=TRUE)
print(args)
"HELLO WORLD" >
So... 1) why did the program create the file 'test1'? This wasn't happening when I started scripting but it appears the first argument in the command prompt becomes a file with some header information and a copy of the program?, 2) PROGOUT.out does contain the 'HELLO WORLD' statement but it does NOT contain any other arguments .... why not and how do I read those arguments into my script.
I could have SWORN this was all working just fine before. Any ideas?
You're looking for Rscript:
Rscript R_ScriptV3.R test1 test2 test3 test4
The params of R CMD BATCH work differently:
R CMD BATCH '--args test1 test2 test3 test4' R_ScriptV3.R output.Rout

Error in R function readGPS: gpsbabel not found

I'm trying to download a gpx file from the YOURS routing API (http://wiki.openstreetmap.org/wiki/YOURS#Routing_API) and upload the file to R using the readGPS function contained in the maptools package.
Here is the code:
require(utils)
require(maptools)
URL <- 'http://www.yournavigation.org/api/1.0/saveas.php?type=gpx&data=5.62373%2053.01,5.62359%2053.01014,5.62336%2053.01024,5.62314%2053.010303'
download.file(URL, 'tmpTrip.gpx')
gpx.raw <- readGPS(i='gpx', f='tmpTrip.gpx', type='t')
And the error I receive:
Error in readGPS(i = "gpx", f = "tmpTrip.gpx", type = "t") :
gpsbabel not found
I do have installed gpsbabel and I can see the gpx file correctly downloaded in my working directory.
My system and R version are:
Windows 7 Enterprise Service Pack 1, running on Intel Core i5-3320M CPU # 2.60GHz, 4GB RAM, 32 bit OS.
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)
Any help is much appreciated, thank you!!
Figuring it out the hard way, I found that readGPS() calls Sys.which which is a function that tries to find where a file is located on the system. ?Sys.which doesn't say it that clearly but (at least on Windows) for it to work, you need to add the install path of gpsbabel to your path.
If you have GPSBabel installed in your working directory as well, this should work.
For me, I changed the WD:
setwd("C:/Program Files (x86)/GPSBabel")
And then my code
gpx.raw <- readGPS(i = "gpx", f = "C:/Users/Desktop/waypoints.gpx", type="w")
worked after that.
For Mac users:
setwd("/Applications/GPSBabelFE.app")

How to make a log-file of an R-session which combines commands, results and warnings/messages/errors from the R-console

I would like to produce a log-file which keeps track of all commands (stdin), results (stdout) and errors/warnings/messages (stderr) in the R console.
I am aware that there are a lot of logging-packages and I tried several like TeachingDemos (seems to ignore stderr completely) or R2HTML (seems to ignore messages), however, none of them seems to include everything from stderr.
Only knitr and markdown seem to be able to include everything into a single file. But using this workaround, I have to write R-scripts and I cannot freely write commands in the console. Furthermore, I cannot include the knitr or markdown command in the same R-script (which is of course a minor problem).
Here is an example:
library(TeachingDemos)
library(R2HTML)
library(TraMineR)
logdir <- "mylog.dir"
txtStart(file=paste(logdir,"test.txt", sep=""), commands=TRUE,
results=TRUE, append=FALSE)
HTMLStart(outdir = logdir, file = "test", echo=TRUE, HTMLframe=FALSE)
## Messages, warnings and errors
message("Print this message.")
warning("Beware.")
"a" + 1
geterrmessage()
## Some example application with the TraMiner package
## which uses messages frequently
data(mvad)
mvad.seq <- seqdef(mvad[, 17:86])
mvad.ham <- seqdist(mvad.seq, method="HAM")
txtStop()
HTMLStop()
If you are running R from a Unix/Linux/Mac/etc. terminal, you can do:
R | tee mydir/mylog.txt
On windows, you can run the script in
R CMD BATCH yourscript.R
and your result will appear in the same folder as yourscript.out
On unices, I've often used the following code idiom with bash:
Some Command 2>&1 | tee NameOfOutputFile.txt
The "2>&1" says to take stderr and redirect it to stdout, which then gets piped to "tee". I will be experimenting with this and other ways of logging an R session.
Another unix trick is the "script" command, which starts a subshell whose I/O (basically everything you type and see in return) is logged to the specified file. And then exit the shell to end the script. Again, subject to experimentation. Since "sink" is native to R, I'll be trying that first.
By the way, I picked these tricks up using solaris, but they work the same running Cygwin, the unix emulator on Windows. Long time ago, I found that my Cygwin images were more up-to-date than the institutional installations of Solaris because the administrators had much more responsibility than just keeping the Solaris up-to-date. Mind you, the institutional machines were more powerful, so even though Cygwin was way more convenient, my personal machine simply didn't fill the need.
AFTERNOTE:
I took example code from page 99 of Shumway's Time Series Analysis and Its Applications With R examples. Here are the contents of a test file palette.R:
r
plot(gnp)
acf2(gnp, 50)
gnpgr = diff(log(gnp)) # growth rate
plot(gnpgr)
acf2(gnpgr, 24)
sarima(gnpgr, 1, 0, 0) # AR(1)
sarima(gnpgr, 0, 0, 2) # MA(2)
ARMAtoMA(ar=.35, ma=0, 10) # prints psi-weights
quit("no")
exit
I invoked it using:
script < palette.R
It captures the commands from palette.R and the corresponding output. So, seems usable for batch mode. For interactive mode, I'm going to go with my original plan and use sink.
I had a similar problem and in my case, I was unable to redirect truly all the output into my log file, as it was dependent on R running in interactive mode.
Specifically, in my log file, I wanted to be able to keep track of the progress bar generated by the rjags::update() function which, however, requires interactive mode:
The progress bar is suppressed if progress.bar is "none" or NULL, if
the update is less than 100 iterations, or if R is not running
interactively.
Therefore, I needed to trick R into thinking that it was running interactively, while it was in fact run from a bash script (interactive_R.sh, below) using here document:
interactive_R.sh
#!/bin/bash
R --interactive << EOT
# R code starts here
print(interactive())
quit("no")
# R code ends here
EOT
(Sidenote: Make sure to avoid the $ character in your R code, as this would not be processed correctly - for example, retrieve a column from a data.frame() by using df[["X1"]] instead of df$X1.)
Then you can simply run this script and send its contents into a log file using the bash command below:
$ ./interactive_R.sh > outputFile.log 2>&1
Your log file will then look as follows:
outputFile.log
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
>
> # R code starts here
> print(interactive())
[1] TRUE
> quit("no")

Resources