error in file(con, "w") - r

This is windows 10 context. R Script (as function) listens to some realtime data and then is supposed to play an audible alarm once some level is tripped. The alarm is activated by a separate function call, and that function simply plays an mp3 file which I play via the following
command: system("powershell.exe", input="C:/Users/ThisUser/Music/Alarms/alarm_alarm_alarm2.mp3").
Additional background is that I'm typically running 3 (or more) other rstudio sessions on the machine. This is the error:
Error in file(con, "w") : cannot open the connection In addition: Warning messages:
1: package ‘httpuv’ was built under R version 3.4.1
2: In file(con, "w") :
cannot open file 'C:\Users\ThisUser\AppData\Local\Temp\Rtmp9w7SM3\file44982a915cf4': No such file or directory
I can test that system command from the console in another rstudio session and it works fine, but if I test in the console of the session where the error resides, I continue to get the error. Also, when I check the tempdir this is what I get:
tempdir()
[1] "C:\Users\ThisUser\AppData\Local\Temp\Rtmp9w7SM3"
Are my other sessions messing up the Temp files or directory path? How can I fix? Thank you.

Related

R: source() cannot open the connection, status was 'Couldn't resolve host name'

I am trying to source a script from my github repo containing functions I use often.
So I have that line at the beginning of my script:
source("https://github.com/jogaudard/common/blob/master/fun-fluxes.R")
In RStudio it returns (same with R in the terminal)
Error in source("https://github.com/jogaudard/common/blob/master/fun-fluxes.R") :
https://github.com/jogaudard/common/blob/master/fun-fluxes.R:6:1: unexpected '<'
5:
6: <
^
In an online R editor I got
Error in file(filename, "r", encoding = encoding) :
cannot open the connection to 'https://github.com/jogaudard/common/blob/master/fun-fluxes.R'
Calls: source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
URL 'https://github.com/jogaudard/common/blob/master/fun-fluxes.R': status was 'Couldn't resolve host name'
Execution halted
I tried with other scripts. I get the same error with anything that is online. source() is working fine with scripts in local (both in the same directory or somewhere else).
It happened since I installed a package that messed a bit with curl. So I thought that might be the issue. But when I tried from another computer I got the same error.
Both computers have R version 3.6.3 on Ubuntu 18.04.5 LTS
I am honestly lost. Cannot find any similar issues anywhere.
You are sourcing a file with html markup and R considers that markup (correctly) to be syntax errors. Use source("https://raw.githubusercontent.com/jogaudard/common/master/fun-fluxes.R") to source the "raw" file.
Your issue with the online R services is a red herring. If you need someone to look into that, you should provide a URL for the service.

Saving a table in HUE from a script executed on the Cloudera Workbench onto my laptop using R

So I have a script written in R that pulls a table, named claims, from HUE. I now need to save that table onto my laptop. I tried this line:
readr::write_csv(claims, "C:/Users/user_name/Desktop/claims.csv")
But go this error message:
Error in open.connection(path, "wb") : cannot open the connection
In addition: Warning message:
In open.connection(path, "wb") :
cannot open file 'C:/Users/A0765618/Desktop/claims.csv': No such file or directory

Could not Publish (TypeError): null is not and object (evaluating b.g.) - Rmarkdown

I'm trying to publish an RMarkdown document to my RPubs account, but I get the next error when clicking on "Publish":
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:/Users/.../File.Rmd': No such file or directory
It also pops up a window saying the next two warnings:
First pop up: "Could not Publish - Error ocurred while executing method"
Second pop up: "Could not Publish - (TypeError): null is not an object evaluating 'b.g.')
My R version is 3.4.2, RStudio version is 1.1.383, knitr version is 1.17.
I have also checked is the working directory contains the files I'm using at the script, and all seems properly set.
This error only happens when I click on Publish. If I try to knit to HTML or to PDF it works. I have tried to restart and reinstall also both R and RStudio but the error persists.
Has anyone had the same error and knows how to solve it?
Thank you very much!
Is the file saved? Are you in the correct directory?
Please check getwd().
I managed to solve it. The problem was that the path of the working directory contained an accent. I changed the path to another folder without accents and it worked.

Connecting to Spark with Sparklyr gives Permission Denied Error

After installing sparklyr package I followed the instruction here ( http://spark.rstudio.com/ ) to connect to spark. But faced with this error. Am I doing something wrong. Please help me.
sc = spark_connect( master = 'local' )
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:\Users\USER\AppData\Local\Temp\RtmpYb3dq4\fileff47b3411ae_spark.log':
Permission denied
But I am able to find the file at the stated location. And on opening, I found it to be empty.I
First of all, did you install sparklyr from github devtools::install_github("rstudio/sparklyr") or CRAN?
There were some issues some time ago with Windows installations.
The issue you have seems to be related to TEMP and TMP folder level permission on Windows or to file creation permission. Every time you start sc <- spark_connect(), it tries to create a folder and file to write the log files.
Make sure you have a write access to these locations.
I could observe the same error message with version 2.4.3 and 2.4.4
in different cases:
When trying to connect to a non "local" master, using spark_connect(master="spark://192.168.0.12:7077", ..),
if the master is not started or not responding at the specified master url.
when setting a specific incomplete configuration
in my case trying to set dynamicAllocation to true, without other required dynamicAllocation settings:
conf <- spark_config()
conf$spark.dynamicAllocation.enabled <- "true"

Installing packages onto R

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.

Resources