Problem with using some R packages. Possible problem in the installation of R?

I'm not sure how to explain this problem, but I think there's an issue in my installation of R.
I'm trying to run an anova on some data I have, and keep getting an error message -

plot(aggregate(Concentration~Ti, FUN=mean, data=datx2))
# Main analysis: between variable is Ti (titanium), within is Day, as each replicate measured at three time points
ANOVA<-aov_ez("id", "Concentration", datx, between = c("Ti"), within = c("Day"))

Error in aov_ez("id", "Concentration", datx, between = c("Ti"), within = c("Day")) : 
  could not find function "aov_ez"

I've uninstalled and reinstalled both R and RStudio. Same problem.
The reason I think it's something in the installation is that I had basically the same problem last year when trying to run a tukey test. Different data, different laptop, but had the same problem.
another reason I think it's the installation is that the exact same code will run perfectly on my supervisors laptop, and my friend's laptop, so something is going wrong with mine and I have absolutely no clue how to fix it.

If anyone could help I would be beyond grateful.
Thanks.

It looks like the function you are trying to use, aov_ez(), is from the afex package. Before you can use a function from that package, you first have to install the package locally. You can think of a package as an app you would download onto your smartphone. Your supervisor probably already has downloaded and installed the afex package on his machine.

Try running:

install.packages("afex")

You only need to install the package one time, but after you have installed the package, before you use it in a script, make sure to load it in your current session by calling:

library(afex)

Hope this helps to get your code running!

2 Likes

I wish that was the solution :frowning:
i didn't put the full code up because i thought it would take up too much room but here it is:

install.packages("afex")
library(afex)

datx <- mfsingle
#datx[which(datx$Ti==15),4] <- 1

# without weird value on 500 (note that this unbalances it)
datx2 <- datx[-20,]

# boxplots at concentrations 
boxplot(Concentration~Ti, data=datx)
boxplot(Concentration~Ti, data=datx2)

# plotted means
plot(aggregate(Concentration~Ti, FUN=mean, data=datx))
#strange low 500 was dragging the mean down
plot(aggregate(Concentration~Ti, FUN=mean, data=datx2))

# Main analysis: between variable is Ti (titanium), within is Day, as each replicate measured at three time points
ANOVA<-aov_ez("id", "Concentration", datx, between = c("Ti"), within = c("Day"))
summary(ANOVA)

which brings up the error in my original post. Again, a similar thing happened last year with a different dataset whilst trying to do a tukey test, yet the exact same thing worked on my supervisors computer.

In your first post, you say you get the following error:

That error suggests to me that the afex package is not installed correctly on your machine. Can you run install.packages("afex", dependencies = TRUE) and then paste any errors you get here?

2 Likes

it worked!!!! Thank you!!!
Why would that have happened, do you know? In case it happens again?

Glad it worked!

Some of the packages that are required for afex to run may have been missing or out of date on your machine. When you specify dependencies = TRUE, R downloads and installs all of these necessary pacakges. You can see the list of packages that afex requires in the "Depends" and "Imports" section of the package overview page.

For more detail and background on package dependencies, take a look at the Dependencies section of Hadley's R Packages book.

Also, if your question has been answered, then please mark the post that answered it as correct for future visitors. The link below will explain how to select a solution: