Why is R not plotting anything and crashes? - r

Suddenly R is not working properly anymore. Everything that requires some sort of visualization causes R to run infinitely and ultimately to crash. Even the simplest code such as: hist(rnorm(50)) does not provide anything. After a while I get a message: "Terminate R, R is not responding to your request to interrupt processing so to stop the current operation you may need to terminate R entirely".
I use a M1 macbook, installed the most recent version of R (v4.2.1. Apple silicon arm64 build for M1 Macs) and RStudio Desktop (2022.07.1+554). All packages are uptodate. I tried restarting R, reinstalling R and dev.off(). All the other functions work fine.
Does anyone know what to do?

I found a solution to my problem. Apparently R was trying to search for a font to use to display images. When I restarted my computer R gave the error message: "In doTryCatch(return(expr), name, parentenv, handler) :
no font could be found for family "Arial" "
A resolution for this problem is provided elsewhere:
RStudio cannot find fonts to be used in plotting

Related

I am getting an error that I do not understand when I try to knit documents on RStudio

I am a relatively new R user. I've been knitting documents in the past using RStudio to create HTML and PDF outputs of my R files.
I have no idea what changed, but approximately 1 month ago I tried to knit a document and got the error portrayed in the picture. I am borderline-competent at R on my best days but otherwise have virtually no knowledge of anything "computer" or "coding" outside of what I've learned from DataCamp regarding R. I have been trying to figure out what happened so that I can continue knitting files, but legitimately do not understand.
I would be more than happy to provide any additional information/context that you need to help me solve this problem but, unfortunately, I just don't know where to start or what's required.
I know this is a bit of a bullshit question and I've tried to avoid asking about it for a while b/c I know I don't know enough to ask it correctly, but I'm at a point where I just want to start knitting again and I'll do whatever it takes to get back to that!
The things I've tried so far are:
Downloading and installing the newest version of R
Downloading and installing RStudio again
Downloading and installing MacTeX again
Trying random solutions from Stack Overflow that involve writing things in my "Terminal" (which I subsequently erase when they don't work).
I am using a MacBook Pro running macOS Catalina 10.15.7 for what it's worth.
I've copied and pasted the text of the error message below:
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
Calls: source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'renv/activate.R': No such file or directory
Execution halted
I had the same error and didn't want to run my Rmd files from the console, so there is the solution for using the button again (which I found here):
> usethis::edit_r_profile()
* Modify 'C:/Users/User/Documents/.Rprofile'
* Restart R for changes to take effect
The output then shows you the path to your file. Just copy that path to the address bar in your explorer and choose the program you want to open it with. I chose the normal text editor. Delete "source('renv/activate.R.')" from this file, restart R, and everything should work fine again.

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.

tryCatch error: the action can´t be completed because the folder is open in RStudio R session

When I download files (Windows 7) using
tryCatch(download.file(paste0(url_bv,arq), paste0(dir_bv,arq))
,error=function(cond) message(paste('erro:',arq,'não encontrado'))
,warning=function(cond) message(paste('warning:',arq,'não encontrado')))
I can´t delete files, getting the msg in the question title.
If I just do
download.file(paste0(url_bv,arq), paste0(dir_bv,arq))
there is no problem.
How can I release the folder/file in R?
I think this is likely a bug in R (windows version). I can faithfully reproduce it in R-3.2.5 (win10_64). I suggest you file a bug report (read R FAQ 9.2 for clear direction).
I tried it with several variations:
different url schemes ("http://" and "https://")
different download.file(..., method=...) options ("wininet", "internal", and "auto" all behaved in this manner; "libcurl" did not, but it merely downloaded the 404.html without telling me there was a problem)
triggers whenever warning=... or condition=... clauses are given to tryCatch and something weird happens in expr
does not trigger with error=... or finally=... arguments
32bit and 64bit variants
not in RStudio
as R --vanilla
All attempted on ubuntu-14.04 (R-3.2.3-64bit) as well, it would not trigger.

Running R code on linux in parallel on computing cluster

I've recently converted my windows R code to a Linux installation for running DEoptim on a function. On my windows system it all worked fine using:
ans <- DEoptim1(Calibrate,lower,upper,
DEoptim.control(trace=TRUE,parallelType=1,parVAr=parVarnames3,
packages=c("hydromad","maptools","compiler","tcltk","raster")))
where the function 'Calibrate' consisted of multiple functions. On the windows system I simply downloaded the various packages needed into the R library. The option paralleType=1 ran the code across a series of cores.
However, now I want to put this code onto a Linux based computing cluster - the function 'Calibrate' works fine when stand alone, as does DEoptim if I want to run the code on one core. However, when I specify the parelleType=1, the code fails and returns:
Error in checkForRemoteErrors(lapply(cl, recvResult)) :
7 nodes produced errors; first error: there is no package called ‘raster’
This error is reproduced whatever package I try and recall, even though the
library(raster)
command worked fine and 'raster' is clearly shown as okay when I call all the libraries using:
library()
So, my gut feeling is, is that even though all the packages and libraries are loaded okay, it is because I have used a personal library and the packages element of DEoptim.control is looking in a different space. An example of how the packages were installed is below:
install.packages("/home/antony/R/Pkges/raster_2.4-15.tar.gz",rpeo=NULL,target="source",lib="/home/antony/R/library")
I also set the lib paths option as below:
.libPaths('/home/antony/R/library')
Has anybody any idea of what I am doing wrong and how to set the 'packages' option in DEoptim control so I can run DEoptim across multiple cores in parallel?
Many thanks, Antony

RStudio : Rook does not work?

I would like to build a simple webserver using Rook, however I am having strange errors when trying it in R-Studio:
The code
library(Rook)
s <- Rhttpd$new()
s$start()
print(s)
returns the rather useless error
"Error in listenPort > 0 :
comparison (6) is possible only for atomic and list types".
When trying the same code in a simple R-Console,everything works - so I would like to understand why that happens and how I can fix it.
RStudio is Version 0.99.484 and R is R 3.2.2
I've experienced same thing.
TLDR: This pull request solves the problem: https://github.com/jeffreyhorner/Rook/pull/31
RStudio is treated in different way and Rook port is same as tools:::httpdPort value. The problem is that in current Rook master tools:::httpdPort is assigned directly. It's a function that's why we need to evaluate it first.
If you want to have it solved right now, without waiting for merge into master: install devtools and load package from my fork #github.
install.packages("devtools")
library(devtools)
install_github("filipstachura/Rook")

Resources