"reached elapsed time limit" warnings RStudio

I am trying to generate a couple of simple plots with ggplot2 to fit 135 data points to lines, but often I receive a warning of the type:

 >Warning message:
In valid.data(rep(units, length.out = length(x)), data) :
  reached elapsed time limit

As a result, sometimes the code executes without generating a plot or generates a plot sluggishly with missing features (legend, titles, etc.). The details of the warning message vary by the name of the function, but it's always because of an 'elapsed time limit reached'. Sometimes simply running library(ggplot2) generates a warning. I am currently using RStudio Version 1.1.463 and R version 3.5.1, but I also tried the latest versions of both software and get the same result. The code runs flawlessly on a colleague's machine with the same software version, which makes me think it's an installation issue, but re-installation did not help. How can I fix the warning messages?

Thanks.

4 Likes

Hi, welcome!

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

Hi and thanks for fixing up my post. I didn't include my code because I noticed it wasn't reproducible on my colleague's machine, but if it helps here is my code:

structure(list(Concentration = c("20%", "50%", "100%", "20%", 
"50%", "100%", "20%", "50%", "100%"), Mass = c(0.01, 0.04, 0.046666667, 
0.02, 0.04, 0.076666667, 0.03, 0.05, 0.09), OD = c(0.405, 0.846, 
1.581, 0.267, 0.645, 1.196, 0.497, 0.992, 1.536), Strain = c("A", 
"A", "A", "B", "B", "B", "C", "C", "C")), class = "data.frame", row.names = c(NA, 
-9L))
#>   Concentration       Mass    OD Strain
#> 1           20% 0.01000000 0.405      A
#> 2           50% 0.04000000 0.846      A
#> 3          100% 0.04666667 1.581      A
#> 4           20% 0.02000000 0.267      B
#> 5           50% 0.04000000 0.645      B
#> 6          100% 0.07666667 1.196      B
#> 7           20% 0.03000000 0.497      C
#> 8           50% 0.05000000 0.992      C
#> 9          100% 0.09000000 1.536      C

Created on 2019-08-02 by the reprex package (v0.3.0)

library(ggplot2)
library(reshape2)
library(gridExtra)
#> Warning: package 'gridExtra' was built under R version 3.5.3

#>rawData = read.csv('MyData.csv',header=TRUE,stringsAsFactors = FALSE)

p1=ggplot(data=rawData,aes(x=`Mass`,y=`OD`))+
  geom_point(data=rawData,aes(x=`Mass`,y=`OD`,colour=`Strain`),size=2)+
  geom_smooth(method = lm,formula=y~x,mapping=NULL, se = TRUE)+
  theme_classic()+
  labs(title="Grouped Fit",x=bquote('Weight [g]'),y=(expression(OD[600]~" [units]")))+
  theme(legend.position="none",plot.title = element_text(hjust = 0.5),aspect.ratio=1,panel.border=element_rect(fill=NA,colour="black"),strip.background = element_rect(colour=NA, fill=NA),axis.text = element_text(colour = "black"),text = element_text(size=10), plot.background = element_rect(fill = "transparent", colour = NA),  legend.background = element_rect(fill="transparent"),legend.key = element_rect(fill = "transparent", colour = "transparent"),panel.background = element_rect(fill = "transparent"))
#> Error in ggplot(data = rawData, aes(x = Mass, y = OD)): object 'rawData' not found


p2=ggplot(data=rawData,aes(x=`Mass`,y=`OD`,colour=`Strain`))+
  geom_point(size=2)+
  geom_smooth(method = lm,formula=y~x,mapping=NULL, se = TRUE)+
  theme_classic()+
  labs(title="Individual Fit",x=bquote('Weight [g]'),y=(expression(OD[600]~" [units]")))+
  theme(legend.position="bottom",plot.title = element_text(hjust = 0.5),aspect.ratio=1,panel.border=element_rect(fill=NA,colour="black"),strip.background = element_rect(colour=NA, fill=NA),axis.text = element_text(colour = "black"),text = element_text(size=10), plot.background = element_rect(fill = "transparent", colour = NA),  legend.background = element_rect(fill="transparent"),legend.key = element_rect(fill = "transparent", colour = "transparent"),panel.background = element_rect(fill = "transparent"))
#> Error in ggplot(data = rawData, aes(x = Mass, y = OD, colour = Strain)): object 'rawData' not found

grid.arrange(p1, p2, nrow = 1)
#> Error in arrangeGrob(...): object 'p1' not found

Created on 2019-08-02 by the reprex package (v0.3.0)

Ironically I got another warning just installing the reprex() package:

package ‘reprex’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
	C:\Users\---\AppData\Local\Temp\Rtmpy2a64d\downloaded_packages
Warning message:
In valid.data(rep(units, length.out = length(x)), data) :
  reached elapsed time limit

I don't think it's an issue with my code, because it runs on base R fine (fast and with no warning messages), but I could be wrong.

I can confirm that your code runs normally on RStudio in my environment, and since you get the same warning while loading reprex, I think this is not related to ggplot2 either. To rule out some common issues I suggest you to try this things.

Thanks for your help andresrcs. Unfortunately none of those suggestions fixed my problem, but I think I figured out how to fix it. I noticed that when I open a script and run it the first time there are no warning messages. It's only when I rerun the script that I get the elapsed time reached messages. I tried adding the line gc() to free up memory from the previous run and I stopped getting the warning messages altogether.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.