How to fix 'tar: Failed to set default locale' error? - r

I'm trying to install a package into R, something I swore on my blood never to do, yet here I am.
The command supposedly goes:
install.packages('NCStats',,'http://www.rforge.net/')`
while I am enjoying the healthy dose of:
Warning: dependencies 'nortest', 'plotrix', 'sciplot', 'car', 'gplots', 'gdata', 'Hmisc', 'TeachingDemos' are not available
trying URL 'http://www.rforge.net/bin/macosx/leopard/contrib/2.11/NCStats_0.1-4.tgz'
Content type 'application/x-gzip' length 237120 bytes (231 Kb)
opened URL
=================================================="
downloaded 231 Kb
tar: Failed to set default locale
The downloaded packages are in
/var/folders/Qj/Qjps7xnxFcWdSHsJY3lo+k+++TI/-Tmp-//RtmpzNO8MM/downloaded_packages`
Le-sigh. Anybody know how I can tell tar what locale I'm in, not that I understand why it needs that or why it can't just know it already?
I'm running OSX 10.6.4 and R 2.11.1 GUI 1.34 Leopard build 64-bit (5589).

Step 1 (In R Console)
system('defaults write org.R-project.R force.LANG en_US.UTF-8')
Step 2: Restart R
Source: http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#Internationalization-of-the-R_002eapp

Use this command in the R console:
system("defaults write org.R-project.R force.LANG en_US.UTF-8")
Remember to quit and start again R.

refer: https://github.com/nerves-project/nerves/issues/376#issuecomment-456939623
If you don't want to permanently set env. variable. do:
$ export LANG=en_US.UTF-8
$ export LC_ALL=$LANG
No need to restart the system.

Better Close the entire R studio and Reopen it again
will fix that error tar: Failed to set default locale

Related

Trouble running whitebox in Rstudio ("~/whitebox_tools.exe" not found)

I am trying to run 'whitebox' packages in R.
To get started, I follow the steps in the link: https://github.com/giswqs/whiteboxR
install.packages("whitebox")
whitebox::install_whitebox()
Console:
------------------------------------------------------------------------
Could not find WhiteboxTools!
------------------------------------------------------------------------
Your next step is to download and install the WhiteboxTools binary:
> whitebox::install_whitebox()
If you have WhiteboxTools installed already run `wbt_init(exe_path=...)`':
> wbt_init(exe_path='/home/user/path/to/whitebox_tools')
For whitebox package documentation, ask for help:
> ??whitebox
For more information visit https://giswqs.github.io/whiteboxR/
------------------------------------------------------------------------
Performing one-time download of WhiteboxTools binary from
https://www.whiteboxgeo.com/WBT_Windows/WhiteboxTools_win_amd64.zip
(This could take a few minutes, please be patient...)
trying URL 'https://www.whiteboxgeo.com/WBT_Windows/WhiteboxTools_win_amd64.zip'
Content type 'application/zip' length 15383844 bytes (14.7 MB)
downloaded 14.7 MB
WhiteboxTools binary is located here: C:/Users/frsu0056/OneDrive - Umeå universitet/Documents/R/win-library/4.1/whitebox/WBT/whitebox_tools.exe
You can now start using whitebox
library(whitebox)
wbt_version()
After downloading i run:
library(whitebox)
if(wbt_init()==TRUE){print("all good")}#confirms if the whitebox_tools.exe exists in,'C:/Users/frsu0056/OneDrive - Umeå universitet/Documents/R/win-library/4.1/whitebox/WBT/whitebox_tools.exe'.
console:
[1] "all good"
Now, if I try to run any function in the whitebox package, it returns an odd error message
for example
wbt_version()
returns:
Error :
Error running WhiteboxTools
whitebox.exe_path: "C:/Users/frsu0056/OneDrive - Umeå universitet/Documents/R/win-library/4.1/whitebox/WBT/whitebox_tools.exe"; File exists? TRUE
Arguments: --version
Error in system(exeargs, intern = TRUE, ignore.stderr = ignore.stderr, : '"C:/Users/frsu0056/OneDrive - Umeå universitet/Documents/R/win-library/4.1/whitebox/WBT/whitebox_tools.exe"' not found
Yet, the wbt_init() returns TRUE so the file exists in the given directory. Nevertheless, the wbt_version() function can not find it.
And so the story goes for any function in the whitebox package. It just can't find the .exe file yet the file exists in the folder where it is supposed to be.
Anyone else get the same problem running this? And what could possibly be wrong here?
Below is the .exe file resting in the directory.
The problem with whitebox in my experience is that it cannot decode spaces. I don't think the problem is the one drive folder per se, just that there are spaces in the file path. I would suggest not having your packages installed in a one drive folder or any other folder where the path has spaces. To change the folder where your libraries are installed, refer to the solution: Change R default library path using .libPaths in Rprofile.site fails to work

Error when trying to install TinyTeX using tinytex R package "cannot contact mirror.ctan.org, returning a backbone server!"

I am trying to use RMarkdown to knit my report to a pdf. I am on my work computer (without administrative privileges and behind a firewall), and chose TinyTeX as a LaTeX distribution because I was hoping it would still work without having to involve the IT department (at my place of work it takes ages to get elevated privileges). I had no problems installing the tinytex R package, but I run into errors when using the package to install TinyTeX. The code with errors is below:
>tinytex::install_tinytex()
trying URL 'http://mirror.ctan.org/systems/texlive/tlnet/install-tl.zip'
trying URL 'http://mirror.ctan.org/systems/texlive/tlnet/install-tl.zip'
Content type 'application/zip' length 22541272 bytes (21.5 MB)
downloaded 21.5 MB
trying URL 'https://yihui.org/gh/tinytex/tools/pkgs-custom.txt'
trying URL 'https://yihui.org/gh/tinytex/tools/pkgs-custom.txt'
Content type 'text/plain; charset=utf-8' length 551 bytes
downloaded 551 bytes
trying URL 'https://yihui.org/gh/tinytex/tools/tinytex.profile'
trying URL 'https://yihui.org/gh/tinytex/tools/tinytex.profile'
Content type 'text/plain; charset=utf-8' length 295 bytes
downloaded 295 bytes
Then at this point I get a dialog box that pops up and states: "Next you may see two error dialog boxes about the missing luatex.dll, and an error message like "Use of uninitialized value in bitwise or (|)..." in the end. These messages can be ignored." When I click 'Okay', I don't see any other dialog boxes but I get the following code:
Starting to install TinyTeX to C:\Users\*****\AppData\Roaming/TinyTeX. It will take a few minutes.
Automated TeX Live installation using profile: ../tinytex.profile
cannot contact mirror.ctan.org, returning a backbone server!
Loading http://www.ctan.org/tex-archive/systems/texlive/tlnet/tlpkg/texlive.tlpdb
C:\Users\*****\AppData\Local\Temp\RtmpgHbZh0\install-tl-20200214\install-tl: TLPDB::from_file could not initialize from: http://www.ctan.org/tex-archive/systems/texlive/tlnet/tlpkg/texlive.tlpdb
C:\Users\*****\AppData\Local\Temp\RtmpgHbZh0\install-tl-20200214\install-tl: Maybe the repository setting should be changed.
C:\Users\*****\AppData\Local\Temp\RtmpgHbZh0\install-tl-20200214\install-tl: More info: https://tug.org/texlive/acquire.html
TinyTeX installed to C:\Users\*****\AppData\Roaming/TinyTeX
Please quit and reopen your R session and IDE (if you are using one, such as RStudio or Emacs) and check if tinytex:::is_tinytex() is TRUE.
Warning messages:
1: In download.file(url, output, ..., method = method) :
URL 'http://mirror.ctan.org/systems/texlive/tlnet/install-tl.zip': status was 'Couldn't connect to server'
2: In download.file(url, output, ..., method = method) :
URL 'https://yihui.org/gh/tinytex/tools/pkgs-custom.txt': status was 'Couldn't connect to server'
3: In download.file(url, output, ..., method = method) :
URL 'https://yihui.org/gh/tinytex/tools/tinytex.profile': status was 'Couldn't connect to server'
4: In file.remove("TinyTeX/install-tl.log") :
cannot remove file 'TinyTeX/install-tl.log', reason 'No such file or directory'
After this, I try tinytex:::is_tinytex() and I get FALSE.
I am using R version 3.6.2, RStudio version 1.2.1335 and I'm on a Windows 10 x64.
I'm not familiar enough with R, RMarkdown or TinyTeX to understand what is going wrong and how to fix it. Perhaps it is because of no admin rights or the firewall...Any help is appreciated!

cannot install tinytex package. (Maybe the repository setting should be changed.)

im using R and quite new at rmarkdown. i want to knit my rmarkdown into pdf formatted file and i already read that i need to install tinytex package.
i enter the code as instructed on https://yihui.org/tinytex/
install.packages('tinytex')
tinytex::install_tinytex()
and i got this error code
Starting to install TinyTeX to C:\Users*****\AppData\Roaming\TinyTeX. It will take a few minutes.
Automated TeX Live installation using profile: ../tinytex.profile
Loading https://mirror.unpad.ac.id/ctan/systems/texlive/tlnet/tlpkg/texlive.tlpdb
C:\Users*****\AppData\Local\Temp\RtmpW6xVT8\install-tl-20191206\install-tl: TLPDB::from_file could not initialize from: https://mirror.unpad.ac.id/ctan/systems/texlive/tlnet/tlpkg/texlive.tlpdb
C:\Users*****\AppData\Local\Temp\RtmpW6xVT8\install-tl-20191206\install-tl: Maybe the repository setting should be changed.
C:\Users*****\AppData\Local\Temp\RtmpW6xVT8\install-tl-20191206\install-tl: More info: https://tug.org/texlive/acquire.html
TinyTeX installed to C:\Users*****\AppData\Roaming\TinyTeX
Please quit and reopen your R session and IDE (if you are using one, such as RStudio or Emacs) and check if tinytex:::is_tinytex() is TRUE.
Warning message:
In file.remove("TinyTeX/install-tl.log") :
cannot remove file 'TinyTeX/install-tl.log', reason 'No such file or directory'
i restart my r and rstudio, run tinytex::is_tinytex(), returned FALSE.
i guess the repository cannot be accessed anymore so i tried to change the repo but still it doesnt change.
can anyone help me with solution? thanks
UPDATE :
i tried to run this as Yihui Xie told me :
tinytex::install_tinytex(repository = 'http://dante.ctan.org/tex-archive/')
and
tinytex::install_tinytex(repository = 'http://mirrors.ibiblio.org/CTAN/')
and return this
trying URL
'http://dante.ctan.org/tex-archive/systems/texlive/tlnet/install-tl.zip'
length 22539829 bytes (21.5 MB) downloaded 21.5 MB trying URL
'https://yihui.name/gh/tinytex/tools/pkgs-custom.txt' Content length
81 bytes downloaded 351 bytes trying URL
'https://yihui.name/gh/tinytex/tools/tinytex.profile' Content length
81 bytes downloaded 295 bytes Starting to install TinyTeX to
C:\Users\Kandu\AppData\Roaming/TinyTeX. It will take a few minutes.
Automated TeX Live installation using profile: ../tinytex.profile
Loading
https://mirror.unpad.ac.id/ctan/systems/texlive/tlnet/tlpkg/texlive.tlpdb
C:\Users\Kandu\AppData\Local\Temp\Rtmp8OFCvK\install-tl-20191209\install-tl:
TLPDB::from_file could not initialize from:
https://mirror.unpad.ac.id/ctan/systems/texlive/tlnet/tlpkg/texlive.tlpdb
C:\Users\Kandu\AppData\Local\Temp\Rtmp8OFCvK\install-tl-20191209\install-tl:
Maybe the repository setting should be changed.
C:\Users\Kandu\AppData\Local\Temp\Rtmp8OFCvK\install-tl-20191209\install-tl:
More info: https://tug.org/texlive/acquire.html TinyTeX installed to
C:\Users\Kandu\AppData\Roaming/TinyTeX Please quit and reopen your R
session and IDE (if you are using one, such as RStudio or Emacs) and
check if tinytex:::is_tinytex() is TRUE. Warning messages:
1: In
file.remove("TinyTeX/install-tl.log") : cannot remove file
'TinyTeX/install-tl.log', reason 'No such file or directory'
2: In
in_dir(target, { : The repository
http://dante.ctan.org/tex-archive/systems/texlive/tlnet does not seem
to be accessible. Reverting to the default CTAN mirror.
idk why but it keep trying to download from https://mirror.unpad.ac.id.
any explanation?
At the moment, the mirror https://mirror.unpad.ac.id does not seem to have a valid SSL certificate, so the site is not accessible. You can find other accessible mirrors at https://ctan.org/mirrors/mirmon. To specify the mirror, use the repository argument. Below are two possible examples:
tinytex::install_tinytex(repository = 'http://mirrors.ibiblio.org/pub/mirrors/CTAN/')
tinytex::install_tinytex(repository = 'http://dante.ctan.org/tex-archive/')

Using install.packages with custom temp dir

I would like to install a package with a security profile that does not have access to /tmp , but has its own temporary directory, for example /tmp/jeroen. However even though I try to pass the TMPDIR environment variable, it still fails because it tries to use /tmp. Below a toy example using RAppArmor and unixtools (see here for the test profile)
> library(RAppArmor)
> library(unixtools)
> dir.create("/tmp/jeroen")
> set.tempdir("/tmp/jeroen")
> setwd(tempdir());
> aa_change_profile("r-test")
Switching profiles...
> print(tempdir());
[1] "/tmp/jeroen"
> install.packages("plyr", lib="/tmp/jeroen", configure.vars="TMPDIR=/tmp/jeroen")
trying URL 'http://cran.rstudio.com/src/contrib/plyr_1.8.tar.gz'
Content type 'application/x-gzip' length 384462 bytes (375 Kb)
opened URL
==================================================
downloaded 375 Kb
Fatal error: cannot create 'R_TempDir'
The downloaded source packages are in
‘/tmp/jeroen/downloaded_packages’
When looking at the kern.log file (which logs security messages), it turns out that the problem is that R CMD INSTALL still tried to use /tmp which was denied:
Jul 24 19:41:34 Jeroen-Antec kernel: [16270.696805] type=1400 audit(1374687694.097:599):
apparmor="DENIED" operation="mkdir" parent=5798 profile="r-test" name="/tmp/RtmpcUOJuQ/"
pid=5802 comm="R" requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000
Is there any way I can tell R CMD INSTALL to use /tmp/jeroen instead?
The correct answer was given by #hadley in the comments: in order to make sure install.packages uses the custom temporary directory, one needs to do
Sys.setenv(TMPDIR="/tmp/jeroen")
in addition to:
configure.vars="TMPDIR=/tmp/jeroen"
This way both the extraction and the installation of the package avoids the system or user default temporary directory.
The documentation in help(tempdir) pretty clearly states that TMP, TMPDIR, ... are used:
By default, ‘tmpdir’ will be the directory given by ‘tempdir()’.
This will be a subdirectory of the per-session temporary directory
found by the following rule when the R session is started. The
environment variables ‘TMPDIR’, ‘TMP’ and ‘TEMP’ are checked in
turn and the first found which points to a writable directory is
used: if none succeeds ‘/tmp’ is used.
So if setting one alone does not help, maybe you want to set several, and make sure the permissions on your 'replacement directory' are permissive enough etc pp.

Cannot install BSDA package into R

I want to use t-test and z-test function, its need to use BSDA package, but
when I install selected, it shows:
trying URL 'http://cran.cnr.Berkeley.edu/bin/macosx/leopard/contrib/2.13/BSDA_1.0.tgz'
Content type 'application/x-gzip' length 833688 bytes (814 Kb)
opened URL
==================================================
downloaded 814 Kb
tar: Failed to set default locale
The downloaded packages are in
/var/folders/4X/4X093vewHqCEqkPJXgl8I++++TI/-Tmp-//RtmpdKKQ3g/downloaded_packages
I don't know why, please help me to tell the mistake. I'm newbie with this program.
Appreciate all answers.
I do not see any problem so far. I get a similar message when I install pkg:BSDA from that CRAN repository (although I did not get the message about not setting a default locale.). That message "packages are in
/var/folders/xS/xSUsVXT..." is generally a sign of success. My guess is that you are a new user and have not yet understood that in addition to installing packages in the Library, which is a durable event, that you also need to load them into your workspace, which is a temporary event, only persisting as long as your session. Try this:
library(BSDA)
If Dirk is correct and that local message is a sign of failure, then in the past some people have reported success with this procedure (to be done in a Terminal session) taken from the Mac-R-FAQ:
defaults write org.R-project.R force.LANG en_US.UTF-8

Resources