2017-05-26 47 views
0

來自R降價收到此錯誤時,我的.RMD莫名其妙的錯誤嘗試嘗試導出時導出我的筆記本電腦 - [R

"Error in filter(Gastropods, Species == "Cellana") : object 'Species' not found Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> filter" 

然而,我所有的地塊都成功地走出來。我可以在數據中清楚地看到,物種欄在那裏,而Cellana是一個物種。沒有拼寫錯誤或任何東西。代碼

我的第20行左右低於

### 
--- 
title: " Lab Report 2 - z5016113" 
output: html_notebook 
i--- 

#1. Gastropod abundance vs. height on the shore 

```{r} 
Gastropods <- read.csv(file = "MaroubraZones.csv", header = TRUE) 
library(ggplot2, dplyr) 
``` 

```{r} 
Gastropods$Zone <- factor(Gastropods$Zone, levels = c("Low", "Mid", "High")) 
``` 

```{r} 
Cellana <- filter(Gastropods, Species == "Cellana") ------> This line is causing the error 
``` 

```{r} 
ggplot(Cellana, aes(Zone, Abundance)) + geom_boxplot() 
``` 
### 
+1

檢查'colnames(腹足動物)',也許將其添加到您的問題。 – Marius

+0

等待,您不要在R代碼中加載'dplyr'或'tidyverse'。在編織時,RMarkdown總會啓動一個新的會話,因此您需要確保以代碼塊加載任何相關的庫。 – Marius

回答

0

看起來這可能是與DPLYR和過濾一個更大的問題,我發現其他職位表明他們有同樣的問題,答案似乎在命令中添加dplyr::filter而不僅僅是filterLink to a similar issue

在將它轉換爲因子之前,通過過濾感興趣的軟體動物來測試它可能也值得嗎?

我也有類似的問題過濾項目出來,並重新啓動R解決了這個問題。

+0

有時你可能會根據加載不同庫的順序來獲得這樣的問題,但是你的回答讓我注意到OP沒有在他的代碼中實際加載'dplyr',這更可能是庫的錯誤源訂單問題。 – Marius

0

dplyr::filter尚未找到,因爲您尚未加載dplyr,但由於在其他軟件包中還有其他函數filter,因此它會嘗試應用這些函數(而不是)。

?library

庫(包,[...])

[...]

給出的名稱的包的名稱,或字面值 字符串或字符串,具體取決於 character.only是否爲FALSE(默認)或TRUE)。

這意味着您一次只能加載一個包。在這裏,您正嘗試在同一個調用中同時加載ggplot2dplyr。僅加載了ggplot2。正確的方法是:

library(dplyr) 
library(ggplot2) 
相關問題