Error: could not find function "read_excel" using R on Mac

user8760612 picture user8760612 · Oct 11, 2017 · Viewed 36.1k times · Source

I am trying to link up my excel data set to R for statistical analysis. I am running on OSX Sierra (10.12.6) with R studio (1.0.153) and Java 8 (update 144).

The function "read_excel" was able to open my excel document a week ago. When I moved the excel and the R document together to another folder, it no longer worked. Reloading the libraries has had no effect. After multiple attempts (and restarting R studio and computer), something finally worked but function "lmer" was no longer found. After reloading library "lme4", "read_excel" no longer worked!

I have also tried using "read.xlsx" and "readWorksheet(loadWorkbook(...))", which didn't work. "read.csv" also did not work properly since the commas were creating disorganized columns and I am dealing with a larger excel workbook with ongoing changes.

Reading on Stack, question Importing .xlsx file into R has not resolved my issue! Please help!

Libraries loaded:

library(multcomp)
library(nlme)
library(XLConnect)
library(XLConnectJars)
library(lme4)
library(car)
library(rJava)
library(xlsx)
library(readxl)

R data file:

Dataset <- read_excel("Example.xlsx",sheet="testing")
#alternative line: Dataset <- read.xlsx("~/Desktop/My Stuff/Sample/Example.xlsx", sheet=7)

Dataset$AAA <- as.factor(Dataset$AAA)
Dataset$BBB <- as.factor(Dataset$BBB)
Dataset$CCC <- as.numeric(Dataset$CCC)
Dataset$DDD <- as.numeric(Dataset$DDD)

Dataset_lme = lmer(CCC ~ AAA + BBB + (1|DDD), data=Dataset)

Answer

carl picture carl · Oct 11, 2017

While you called the library, try and see if adding readxl::read_excel(path = "yourPath",sheet=1), or even remove the sheet reference. It will automatically take the first sheet.