R error-normalizePath(path.expand(path), winslash, mustWork) - r

I was provided a new work computer and I was granted admin rights for the weekend. I installed R version 4.2 but get this error when it starts up:
normalizePath(path.expand(path), winslash, mustWork) :
path[1]="P:": The network path was not found
Because it is trying to connect to my shared Drive "P" first, it is a slow process each time I start R or R Studio.
When I am not connected to the network it is faster but only after it searches for the P drive and goes through the error.
This is a slow process. If I could have it normalizePath(path.expand(path)) the "C" drive instead of "P", it would make things much faster.
Is there a way to have it go directly to the C Drive? I have tried to change the .Rprofile but it doesn't help because it still searches the shared P Drive on the R startup.
Any help on preventing it from going to the shared drive and getting stuck would be appreciated.
Thank you.

Related

Error when installing the 'graphics' package (but not others) in R

I am a starter in R and new to StackOverflow and this is the first time I raise a question, I hope i'm following all the rules...
Anyway. I got R (3.5.0 version) and R-Studio on my laptop with Win 10 Home installed (under the same parent folder 'D:\') and reset the temporary file directory to a folder in D:\ so that the Chinese in C:\Users\中文\documents (which is the default place for tempo files) doesn't affect the connection btw R-studio and R (I was told any relevant directory has to be in English to make R-Studio work).
The problem is, I cannot install the 'graphics' package when I run
install.packages('graphics')
The resulting error says something like this:
>Error in install.packages : Updating loaded packages
>Restarting R session...
>Error in gzfile(file, "wb") : cannot open the connection
>Error saving session (options): R code execution error
>WARNING: Forcing suspend of process in spite of all session data not being fully saved.
It's quite weird since the 'graphics' package is pretty basic and as a matter of fact I haven't found anyone reporting such errors on the internet.
It also bothers me that other packages like 'forecast' and 'XML' can be successfully installed without any error report.
I've looked at some similar questions on StackOverflow, having error reports with "Error in gzfile(file, "wb") : cannot open the connection", but they all seem to have something else to complete the sentence. In my case it just stops the error description with "cannot open the connection". Also I couldn't find people having similar problems with "Error saving session (options): R code execution error".
I do realize that this is quite unusual. I can't even find the proper tags other than r for this question. Although it seems that no one has trouble with the 'graphics', this problem is really bothering me and I hope someone can give possible solutions. Thanks a lot.

RStudio: unexpected call to `dir.create()` with the first instruction within a project stored on a network drive

First, apologies for a lack of a reproducible example, but I cannot really provide one as I believe the problem lies within my network settings. Please treat this question as a call for help in debugging the issue...
After opening in RStudio a project stored on a network drive and running the very first instruction (being it a package load or even a <- 1) I am seeing a really weird output in the console:
> a <- 1
Warning message:
In dir.create(tempPath, recursive = TRUE) :
cannot create dir 'F:\Marketing', reason 'Permission denied'
I have all possible temp dirs set up in user environment variables (TEMP, TMP, TMPDIR) and Sys.getenv() is printing them correctly.
"F:\Marketing" is a valid path on my network drive and it is a root directory of the project.
I have tried to debugonce(dir.create) in .RProfile to see what the tempPath is, but unfortunately this resulted in an "invalid 'envir' argument" error.
After copying the project to a local drive the problem disappears, so this is clearly a network drive/network setup problem, but I do not know where to dig more and my IT dept. is not really useful here...
Any ideas how to debug this warning?

Error while using h2o.init in R

This is the error message:
> h2o.init()
Error in dirname(path) : path too long
In addition: There were 12 warnings (use warnings() to see them)
This is one of the warning messages (the others are similar):
> warnings()
Warning messages:
1: In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="\\FILE-EM1-06/USERDATA2$/john134/My Documents/./../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../..": The filename or extension is too long
Any idea how to work around this error?
Thanks
It seems that Windows path string is limited to (maybe) 256 length. Usually, setting a the path setwd(shorterExistingWorkDir) works and should address your issue.
I struggled with this issue quite a bit, including upgrading.
Most folks are assuming that you've literally just set an incredibly long path. I don't think this is the case (it wasn't for me, at least). It's that the PATH may be set on a network drive or other device where the underlying mapped paths are more complicated.
A related thread is here on the H2O forum:
Main issue is the user had a Windows drive that did not conform to the norm, i.e., "C://", etc. Instead, the user had a network drive
(DTCHYB-AZPX015/). This caused issues in the search for a config
file as there was no "root" (In this case, "root" is reaching your Win
drive). Since there was no "root", the path to search kept expanding
until it caused R to error out with the above exception.
The fix is to NOT search for a config when h2o.init() is called. Rather, only search for a config if a user asks to do so. My proposal
is to add a new field to h2o.init()called ignore_config. This
field will be set to TRUE by default.
When calling h2o.init() the R environment signal the launching of h2o application (actually a web server) in the backend which was installed when you install H2O package into R. The local runtime environment uses the full path of the location where H2O jar file is located. Because the packages is installed deep inside the nested folders in your file system it cross the valid limit of OS path 256 character length and fails to launch the backend H2O server and you see this error. In your case you are using external path so adds up more characters in the path to make the problem worse..
For example the h2o.jar is located in my OSX machine as below:
/Library/Frameworks/R.framework/Resources/library/h2o <-- H2O package Path
/Library/Frameworks/R.framework/Resources/library/h2o/java/h2o.jar <-- Jar Path
As you are using Windows, what you need is to find ways to reduce this path to OS limit and it will work.
The other solution is to run h2o.jar separately and then just use R to connect to H2O cluster. The steps are as below:
Download H2O 3.10.4.2 and unzip to a folder close to root so you do not hit 265 char limit again. Also install 3.10.4.2 R Package. (Try to keep the same version)
Run H2O > java -jar h2o.jar
From RStudio console try > h2o.init()
So if there is already H2O cluster running the h2o.init() will connect to a running H2O cluster instead to start one and you will by pass above problem.
If you hit any problem write here and we will help you.

Launching R help: Error in file(out, "wt") : cannot open the connection

I want to launch R help, I type ?dir.create. It is giving me this strange error:
Error in file(out, "wt") : cannot open the connection
In addition: Warning message:
In file(out, "wt") :
cannot open file
'C:\Users\XYZ~1\AppData\Local\Temp\Rtmp86bEoJ\Rtxt32dcef24de2': No
such file or directory
Please help me. What do I do to overcome this problem? Even googling this problem didn't give me much info.
This happens when the temporary directory used by R is deleted. This usually happens when user or the system cleans up the tmp directory while the R session is running. Typically happens if the R session is open for a long time.
Remedy is very simple. You don't actually need to restart R. Just re-create the temporary directory by:
tempdir()
# [1] "C:\Users\XYZ~1\AppData\Local\Temp\Rtmp86bEoJ\Rtxt32dcef24de2"
dir.create(tempdir())
NOTE: this happens to me more and more often in Windows 10... even within like 8 hour session only! Not sure why this happens. See this question: https://superuser.com/questions/1502272/windows-10-cleaning-up-my-temp-dir-too-often
Ok.Thank you all.I was able to resolve this by changing the directory and exiting R and re-logging into swirl.

r - How to specify the path in normalizePath, or get around this error associated with it?

I'm learning R and just have it installed on my office computer. I don't have the administrator right on the computer (as I even have to call IT for installation).
Then I install a package. At first it doesn't work when typing, for example:
install.packages("thepackage")
The error message is this:
Error in normalizePath(path.expand(path), winslash, mustWork) :
path[1]="\\company\5050\Users\myusername\Documents\R\win-library\3.3": Access is denied
In addition: Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="\\company/5050/Users/myusername/Documents/R/win-library/3.3": Access is denied
I do some homework and find that a potential solution is to "Map a network drive to your network folder". I'm not sure what it means, but I try this:
install.packages("thepackage",lib="H:/Documents/R/win-library/3.3")
because it looks like I have more "control" of H drive (it has my username on it). And it works:
package ‘thepackage’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\myusername\AppData\Local\Temp\Rtmp4MNURu\downloaded_packages
I then fail to load the package,
library(thepackage)
saying:
Error in normalizePath(path.expand(path), winslash, mustWork) :
path[1]="\\company/5050/Users/myusername/Documents/R/win-library/3.3": Access is denied
But again this works:
library(thepackage,lib="H:/Documents/R/win-library/3.3")
So how can I set the normalizePath to the one that works to avoid additional and rather unnecessary specification of library directory?
You can put in your home directory's .Rprofile file (just create it if it's not there yet) the following line:
.libPaths("H:/Documents/R/win-library/3.3")
That way this location will be used by default. The .Rprofile is run every time you're opening any new R session. You can copy the existing content of the folder from which you don't have write access to this folder to include all pre-installed packages.
I think you are looking for:
system("net use D: \\\\company\\path\\")
to map to the virtual D drive. I would then use file.path when accessing the stuff on D:. It looks that you may benefit from changing R defalut library path in Rprofile.site, by adding the line:
.libPaths("Path to your libs")
When you type .libPaths() can you read and write to that directory with no problems?
I was with the same problem them I found this solution by the user Mike M.
In Windows 10/11 you can also set the R Home Directory just for R
without changing your system HOME with a special environment variable
R_USER. Adding this to your Environment Variables with the path you
want for your R Home will set the R Home path without changing your
system HOME. RStudio looks for R_USER first (and then moves on to
HOME).
It worked for me.

Resources