Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

macos

r

readxl

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)
like image 618
user8760612 Avatar asked Oct 11 '17 18:10

user8760612


3 Answers

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.

like image 158
carl Avatar answered Oct 06 '22 00:10

carl


Perhaps, when you moved the excel and R file to another folder, the pathway should be change either. Try change the pathway, or replace the pathay by file.choose() and search the excel file manually. You called the package "xlsx", which can do the thing what you need. Maybe you're typing it wrong.

Dataset <- read.xlsx("Example.xlsx",sheetName="testing")

or

Dataset <- read.xlsx("Example.xlsx",sheetIndex="number of the excel sheet")

I hope it helps.

like image 23
Luis Antolin Avatar answered Oct 05 '22 23:10

Luis Antolin


Try activating library(tidyverse) and library(readr) then use the read_excel().This should work.

like image 22
Abhijit Pai Avatar answered Oct 05 '22 23:10

Abhijit Pai