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

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?

Related

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 can I install and use (mice) function in R?

I want to use mice function to handle the missing data that I have in (data). I installed the package and I called the library. However, when I am trying to apply the function to my data it gives me error as below:
(Error in mice(data[, 5:9], m = 3, seed = 123) :
could not find function "mice")
I have a normal data frame that includes NAs
install.packages('mice')
library(mice)
library(VIM)
md.pattern(data)
md.pairs(data)
My_New_Data <- mice(data[,5:9], m=3, seed=123)
I am expecting the function to solve the problem and replace the NAs with reasonable values. It did not work at all!
Edit (incorporating comment suggestion)
In the comments the running mice::mice(data[, 5:9], m = 3, seed = 123). I ran this and the following error was returned.
Error in get(Info[i, 1], envir = env):
lazy-load database 'C:/Users/MUSTAFA KAMAL/Documents/R/win-library/3.5/broom/R/broom.rdb' is corrupt
In addition:
Warning message: In get(Info[i, 1], envir = env) : internal error -3 in R_decompress1
In order to incorporate an answer to this question, I will rewrite my comment which resolved the problem, in the form of a short answer.
From the comments executing mice::mice(data[, 5:9], m = 3, seed = 123) resulted in an error message, showing the directory ~/Documents/R/win-library/**3.5**/broom/R/broom.rdb being corrupt.
From the corrupted directory path, one can see that OP was running R-3.5.x, while the newest version is R-3.6.x. Some packages updated since the most recent R-update has experienced similar problems, as such a first step towards solving these types of issues is updating R. The installr contains the function updateR which can help smooth over such updates, while also updating any outdated packages.
As a side note, an update sometimes fails to update the actual packages or results in other packages being corrupted, as such if an error persists one solution is to simply delete and re-install the package (or the entire ~/Documents/R/win-library/3.z/ directory). In the question from OP the corrupt package is the broom package, as such one could re-install this package by running
remove.packages("broom")
install.packages("broom")
which should resolve any leftover issues. Note however multiple packages might be corrupt, and likely only one will be shown every time the function is executed. In such cases a full package clear will do the trick, but requires re-installing all packages. For this one can export all installed packages prior to removing them all, by noting that a full list of installed packages is contained in installed.packages(), which can then be exported to a file with for example write.table or write.csv.

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

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.

Error in clusplot function

I am playing with cluster analysis in R and I would like to plot the cluster:
teste<-data.frame(v1=rnorm(100),v2=rexp(100),v3=runif(100) )
fit.c<- kmeans(teste,2)
aggregate(teste,by=list(fit.c$cluster),FUN=mean)
clusplot(teste, fit.c$cluster, color=TRUE, shade=TRUE,labels=2, lines=0)
But it gives me this error:
Error in clusplot.default(teste, fit.c$cluster, color = TRUE, shade = TRUE, :
4 arguments passed to .Internal(nchar) which requires 3
Does anyone know what is happening?
Thank you
I ran your code and got no problems. I am guessing that there is a version mismatch between your R and the packages you are using. Can you make sure that your cluster package is up to date (and any other packages you are using for that matter), and/or update to the latest version of R?
If that doesn't work, can you add the sessionInfo() information? That is often helpful for diagnosing these sorts of problems.

Resources