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.
Related
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
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/')
I'm having trouble roxygenizing a package. It was last working several months ago and I haven't checked since, so not sure if a snippet of code I added broke it, if my system's configuration changed, or if roxygen2 changed.
I've tried calling it through devtools::document, in a --vanilla R sesssion with roxygen2::roxygenize('taRifx') from the directory above it, roxygenize('.') from the project base directory, tried running as root in case it was a permissions thing, etc.
Here's the RStudio version:
==> roxygenize('.', roclets=c('rd'))
* checking for changes ... ERROR
Error in file(con, "r") : cannot open the connection
Package code is here:
https://github.com/gsk3/taRifx
How do I fix this?
You'll need to change line 1242 of the Rfunctions.R file to #examples instead of #example. For proper formatting you'll also need to change the # in email addresses to ##.
For some reason I am suddenly not able to install packages in R (I have subsequently updated to the latest version of R and am running Windows 7). For example, if I type:
install.packages('beeswarm')
Installing package into ‘D:/Rlibs’ (as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session --- trying URL 'http://www.stats.bris.ac.uk/R/bin/windows/contrib/3.0/beeswarm_0.1.5.zip'
Content type 'text/html' length unknown opened URL downloaded 1859
bytes
Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package",
"Type")) : cannot open the connection In addition: Warning
messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting
from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"),
c("Package", "Type")) : cannot open compressed file
'beeswarm/DESCRIPTION', probable reason 'No such file or directory'
I have read that in Windows 7 there can be important restrictions on rights to writing to certain folders etc. so I've gone to some lengths to install R and library folders in non-default areas of my computer, and to allow myself rights to certain folders, but to no avail. Possibly also of importance is when I type:
.libPaths()
# [1] "D:/Rlibs"
# [2] "C:/Users/L.Halsey/Documents/R/win-library/3.0"
# [3] "C:/Users/L.Halsey/Documents/Documents/R-3.0.1/library"
I have created several folders in an attempt to create one that I could successfully install libraries into and set them up to be recognised by R using 'environment variables' from the start button. I don't know how to delete any of them though - not sure if this is relevant to my overall problem of not now being able to install/update packages for some reason.
The error being reported is inability to open a connection. In Windows that is often a firewall problem and is in the Windows R FAQ. The usual first attempt should be to run internet2.dll. From a console session you can use:
setInternet2(TRUE)
(You are correct in thinking this is not due to your library setup. The error says nothing about permissions.) I don't think just typing .libPaths should return that character vector since on my machine I would need to type .libPaths() to see something like that. If you wanted to reduce the number of places for libraries you can use the .libPaths function for setting the values. This would pick the second and third of the existing paths
.libPaths( .libPaths()[2:3] )
The inner call retrieves the path vector and the outer call sets it to a reduced vector.
Running RStudio as administrator fixed it for me!
I will probably duplicate a lot of other answers on the stackoverflow, but I got exactly the same error as OP, namely:
Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open compressed file 'zoo/DESCRIPTION', probable reason 'No such file or directory'
Turned out, while I as a user had permissions to write in a certain directory, R did not. In order to be sure you don't have something similar, do following:
get a usb drive, let's name it E
download package source as a .zip file and store it onto usb-drive in some directory, let's name it E:/source
Create directory for libraries on the usb drive, let's name it E:/libs
Install packages calling R command install.package from the R console and setting all relevant directories to point to your usb drive:
(here I use package zoo as an example)
install.packages("E:/source/zoo_1.7-12.zip",
destdir = 'E:/source', # no "/" after the path
lib = 'E:/libs',
repos = NULL)
Load the package from the directory, where you installed it:
library('zoo', lib.loc = 'E:/libs')
After you are sure, it works this way on your usb drive, you can start resolving directories permissions, and try out by changing the paths in the code above.
update:
In some windows environments even your usb-stick might be protected from read-write by the R. Make sure you check the permissions using the machine you are working from.
The following worked for me (based on the answer above)
install.packages("clustvarsel", lib = "C:/Users/dnentchev/My Programs/R-3.2.2/library")
I had the same problem. I turned the windows firewall off, and Run RStudio as administrator. so, that error fixed.
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