简体   繁体   English

错误:在 Mac 上使用 R 找不到函数“read_excel”

[英]Error: could not find function “read_excel” using R on Mac

I am trying to link up my excel data set to R for statistical analysis.我正在尝试将我的 excel 数据集链接到 R 进行统计分析。 I am running on OSX Sierra (10.12.6) with R studio (1.0.153) and Java 8 (update 144).我在 OSX Sierra (10.12.6) 和 R studio (1.0.153) 和 Java 8 (update 144) 上运行。

The function "read_excel" was able to open my excel document a week ago.一周前,函数“read_excel”能够打开我的 excel 文档。 When I moved the excel and the R document together to another folder, it no longer worked.当我将 excel 和 R 文档一起移动到另一个文件夹时,它不再起作用。 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.经过多次尝试(并重新启动 R Studio 和计算机),终于找到了一些东西,但不再找到函数“lmer”。 After reloading library "lme4", "read_excel" no longer worked!重新加载库“lme4”后,“read_excel”不再起作用!

I have also tried using "read.xlsx" and "readWorksheet(loadWorkbook(...))", which didn't work.我也试过使用“read.xlsx”和“readWorksheet(loadWorkbook(...))”,但没有用。 "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. “read.csv”也无法正常工作,因为逗号正在创建杂乱无章的列,而我正在处理一个更大的 excel 工作簿,并且正在进行更改。

Reading on Stack, question Importing .xlsx file into R has not resolved my issue!在堆栈上阅读,问题将 .xlsx 文件导入 R并没有解决我的问题! 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: R数据文件:

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)

While you called the library, try and see if adding readxl::read_excel(path = "yourPath",sheet=1), or even remove the sheet reference.在调用库时,尝试查看是否添加 readxl::read_excel(path = "yourPath",sheet=1),甚至删除工作表引用。 It will automatically take the first sheet.它将自动取第一张纸。

Perhaps, when you moved the excel and R file to another folder, the pathway should be change either.也许,当您将 excel 和 R 文件移动到另一个文件夹时,路径也应该更改。 Try change the pathway, or replace the pathay by file.choose() and search the excel file manually.尝试更改路径,或用file.choose()替换路径并手动搜索 excel 文件。 You called the package "xlsx", which can do the thing what you need.您将包称为“xlsx”,它可以满足您的需求。 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.我希望它有帮助。

尝试激活 library(tidyverse) 和 library(readr) 然后使用 read_excel()。这应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM