I am writing a stats assignment in rmarkdown. It all runs fine except when I try to knit it, I get an error that an object that I defined in a prior chunk is not found. I've read a lot about this and tried some solutions but I still cannot get it to work.
Here is the code:
library(vegan) library(magrittr) library(labdsv) # Load data Oak <- read.csv("Oak_data_47x216.csv", header = TRUE, row.names = 1) Oak_spp <- read.csv("Oak_species_189x5.csv", header = TRUE) ## subset data ; all plots with elevation > 100 # subset explanatory and response variables Oak.JH <- Oak[Oak$Elev.m > 100, ] nrow(Oak.JH)/nrow(Oak) ## 75% of the plots Oak.JH.abund<-Oak.JH[, colnames(Oak) %in% Oak_spp$SpeciesCode] Oak.JH.explan<-Oak.JH[, !colnames(Oak) %in% Oak_spp$SpeciesCode]
Oak.JH1 <- Oak.JH.abund %>% vegtab(minval = 0.05 * nrow(Oak.JH.abund)) %>% # Remove rare species decostand("max") # Relativize by species maxima
Here is where I get the error when trying to knit
Line 83: Error in eval(expr, envir, enclose): object 'Oak.JH' not found Calls: >Anonymous>... handle -> withcallingHandelrs -> withVisible -> eval -> eval Execution halted
My working directory is set to the same spot as the .rmd file, and the code works fine when I run it normally (Ctrl+enter)
Thanks for any help