DataTable warning table ajax error for some people but not all with shiny - r

I recieved such error when, in created shiny app in R with DataTables packages in my mobile and one laptop. However, it didn't throw error with other laptops, Same code was working yesterday, and day before yesterday. I haven't changed code, but it is throwing error.
Why there is problem with some devices but not all devices. I used other devices, those devices are not throwing error.
Any idea how to fix this problem? The solution for this problem should be explained here http://datatables.net/manual/tech-notes/7
What is issue ?
Following is thrown error as follows:
DataTables warning: table id=DataTables_Table_0 - Ajax error. For more
information about this error, please see http://datatables.net/tn/7

I am also suffering. Please take a look at the discussion of this issue #269 on Github.
It seems to be a problem post version 0.1 where you need to "flatten" variables using as.numeric.
ISSUE
Example and solution given by XD-DENG was and to quote them:
"The error is gone when I use
temp <- tapply(iris$Sepal.Length, iris$Species, mean)
result <- data.frame(species = names(temp),
mean = as.numeric(temp))
return(result)
instead of:
temp <- tapply(iris$Sepal.Length, iris$Species, mean)
result <- data.frame(species = names(temp),
mean = temp)
return(result)
The main difference is whether the column mean has additional attribution, dimension. This is what caused the error.
But it's still weird given version 0.1 of DT works perfectly on both."
PATCH
#yihui has pushed a fix for this to the dev version so please try update your DT package. (You can use package devtools to install from github devtools::install_github('rstudio/DT'))
I hope this fixes this intermittent error.

I just explicitly made as.numeric() to all numeric columns within my data.frame (though they are already numeric when I do str()) and the problem is gone.

Related

Error when using ggstatsplot - Error in 'mutate()': Caused by error in vapply()':

Just installed ggstatsplot and tried running the Example in the Documentation to just see what inputs it requires and how to manipulate the function.
library(ggstatsplot)
ggbetweenstats(mtcars, am, mpg)
I was immediately met with the error:
Error in `mutate()`:
! Problem while computing `n_label = paste0(am, "\n(n = ", .prettyNum(n), ")")`.
Caused by error in `vapply()`:
! values must be length 1,
but FUN(X[[1]]) result is length 3
I have tried multiple examples I found online of how to use the package and all result in the same error. I also tried ggwithinstats and received the same error. I updated all of my packages and have restarted R Studio at each step.
Any help would be appreciated, please let me know if I can provide any other information.
Sorry for the troubles.
This is due to update to insight package (https://github.com/IndrajeetPatil/ggstatsplot/issues/749).
EDIT on 21 May 22:
Both statsExpressions and ggstatsplot updates are now on CRAN, so all these issues should go away.
I get the exact same error.
#for reproducibility and data
set.seed(123)
library(WRS2)
library(ggstatsplot)
ggwithinstats(
data = bugs_long,
x = condition,
y = desire
)
May it is a bug?

truthTable in Rstudio Error: incorrect outcome specification

I was trying to do a QCA analysis of sufficeny in RStudio 4.1.3. using truthTable command. By running the code i get Error: wrong outcome specification. The outcome is written correctly. When I do an analysis of necessity with superSubset code everything works fine. Everything is coded numeric but it does not work with bivariate callibration either.
> ttCO21 <- truthTable( data = mydata, outcome = "CO21",
+ conditions = "GENDG1, FDI1, GDP1",
+ sort.by="incl, n", show.cases = TRUE, complete = TRUE)
**Error: Incorrect outcome specification.**
I had the same issue today and the solution was to delete any unnecessary columns (or create a new dataframe). I left only the calibrated conditions and outcome, because when I found this error, the raw data was in the same df, even if was not using it in the truthTable() command.
Because of the 3 hours i wasted on this problem i'll share my situation and solution. I had the exact same problem. creating a new df did not help, nor did removing unnecessary colums (wouldn't make sense anyway). Completely reinstalling en reloading the QCA package did work for me. Hope this helps someone.
you can try "comma" instead of "dot" (in “decimal") when you import file

ggplot2 error: Error in default + theme : non-numeric argument to binary operator

I have been getting the error Error in default + theme : non-numeric argument to binary operator. I have been using R and teaching R for a long time but I can't find this problem. I have included a reproducible example that fails this way below:
library(tibble)
library(ggplot2)
brains <- as_tibble(brains)
brains <- brains[1:10, ]
brains
ggplot(brains, aes(x = BodyWt, y = BrainWt)) +
geom_point()
The error occurs when executing the ggplot() statement.
My hardware is an HP Laptop 15-ef0xxx. I am running Windows 10 Home version 2004. I am running RStudio community edition "Water Lily" and R version R x64** 4.0.2.
I know this is a simple error and it is driving me crazy.
So I finally solved this problem. On the github issue I had opened Hiroaki commented that "One possibility is that you might set a invalid default theme in your .Rprofile, but I'm not sure..." (see link to issue below).
I'm not sure if your R file is part of a project but mine is.
So I went back and deleted the theme_set() line in my R file, went in and double checked all my project options and selected the option "Disable .Rprofile execution on session start/resume" and "Quit child processes on exit". And then I restarted the R session and now everything works. Including on the default R editor console.
I'm not sure if all those steps are necessary but that seemed to do the trick for me! Hope it helps.
I thought this was an RStudio issue but it seems it's possibly a ggplot2 > problem. I have verified using two different datasets that the same >error comes up when I try using ggplot2 in RStudio or using the default R >console. I get the exact same error with code that's been working fine >but now suddenly won't. I have opened an issue on Github (ggplot2) with a >reprex. Might be worth checking there: >https://github.com/tidyverse/ggplot2/issues/4177
I know this is not an answer per se but I don't have enough reputation >points to add a comment to the previous answer but I thought linking to >the issue on Github might help.
I think you have numbers quoted somewhere and you are trying to perform mathematical operation on character values. Consider
x <- c("5","6")
y <- x/1
> y <- x/1
Error in x/1 : non-numeric argument to binary operator
Now try converting x to numeric and perform the same operation.
y <- as.numeric(x)/1
> y
[1] 5 6
So, you need to use as.numeric on your variable.
The following should resove this issue
ggplot(brains, aes(x = as.numeric(BodyWt), y = as.numeric(BrainWt)))

How to fix lmer error: "Error in as(value, fieldClass, strict=FALSE) :"?

I'm getting a strange error when I run an lmer function in r.
I've tried changing the variable types (all of them are numeric or factor) and removing the NA before analysis, but nothing seems to work.
model_1 <- lmer(Q14 ~ gender * time + (1|OMID), data=data)
summary(model_1)
Specifically, my error message reads:
Error in as(value, fieldClass, strict = FALSE) :
internal problem in as(): “labelled” is(object, "numeric") is TRUE, but the metadata asserts that the 'is' relation is FALSE
Not sure why this is happening, but I can't seem to find any answers for it. Any help would be appreciated.
Thanks!
I think lmer has a problem with 'labelled' data. If you un-label the predictors it should work fine.
I had the same error: the code for the lme-formula worked perfectly fine and one day I encountered that error. The solution in my case was simply to restart the R session, reload the data - in my case from SPSS via library("haven")::read.sps and after that load library("lme4") and execute the lme-formula.
So, if the formula worked before without any error, maybe just clean the project environment and re-run the most crucial code without any additional packages loaded. Maybe it's just some "cross-contamination" between packages or an unwanted effect of any package on the dataframe.

How do I close unused connections after read_html in R

I am quite new to R and am trying to access some information on the internet, but am having problems with connections that don't seem to be closing. I would really appreciate it if someone here could give me some advice...
Originally I wanted to use the WebChem package, which theoretically delivers everything I want, but when some of the output data is missing from the webpage, WebChem doesn't return any data from that page. To get around this, I have taken most of the code from the package but altered it slightly to fit my needs. This worked fine, for about the first 150 usages, but now, although I have changed nothing, when I use the command read_html, I get the warning message " closing unused connection 4 (http:....." Although this is only a warning message, read_html doesn't return anything after this warning is generated.
I have written a simplified code, given below. This has the same problem
Closing R completely (or even rebooting my PC) doesn't seem to make a difference - the warning message now appears the second time I use the code. I can run the querys one at a time, outside of the loop with no problems, but as soon as I try to use the loop, the error occurs again on the 2nd iteration.
I have tried to vectorise the code, and again it returned the same error message.
I tried showConnections(all=TRUE), but only got connections 0-2 for stdin, stdout, stderr.
I have tried searching for ways to close the html connection, but I can't define the url as a con, and close(qurl) and close(ttt) also don't work. (Return errors of no applicable method for 'close' applied to an object of class "character and no applicable method for 'close' applied to an object of class "c('xml_document', 'xml_node')", repectively)
Does anybody know a way to close these connections so that they don't break my routine? Any suggestions would be very welcome. Thanks!
PS: I am using R version 3.3.0 with RStudio Version 0.99.902.
CasNrs <- c("630-08-0","463-49-0","194-59-2","86-74-8","148-79-8")
tit = character()
for (i in 1:length(CasNrs)){
CurrCasNr <- as.character(CasNrs[i])
baseurl <- 'http://chem.sis.nlm.nih.gov/chemidplus/rn/'
qurl <- paste0(baseurl, CurrCasNr, '?DT_START_ROW=0&DT_ROWS_PER_PAGE=50')
ttt <- try(read_html(qurl), silent = TRUE)
tit[i] <- xml_text(xml_find_all(ttt, "//head/title"))
}
After researching the topic I came up with the following solution:
url <- "https://website_example.com"
url = url(url, "rb")
html <- read_html(url)
close(url)
# + Whatever you wanna do with the html since it's already saved!
I haven't found a good answer for this problem. The best work-around that I came up with is to include the function below, with Secs = 3 or 4. I still don't know why the problem occurs or how to stop it without building in a large delay.
CatchupPause <- function(Secs){
Sys.sleep(Secs) #pause to let connection work
closeAllConnections()
gc()
}
I found this post as I was running into the same problems when I tried to scrape multiple datasets in the same script. The script would get progressively slower and I feel it was due to the connections. Here is a simple loop that closes out all of the connections.
for (i in seq_along(df$URLs)){function(i)
closeAllConnections(i)
}

Resources