4
votes

So I'm doing some statistical analysis in R and I would like to have the output in a markdown file. The code works perfectly when using it in my R session but when I knit the file to pdf none of my objects can be found.

So I read in the data and do some minor adjustments which works out fine. Though in the second block it can't find the object RESP which is one of the columns in my data frame. I tried phrasing it as scallopData$RESP but then it can't find the object scallopData so that doesn't help.

```{r}
setwd("C:/Users/Zokids/Desktop/R-studio")

scallopData <- read.table("scallopDATA.csv", header = T, sep = ";", na.strings = "NA", dec = ",")
scallopData$pH <- as.factor(scallopData$pH)
scallopData$Temperature <- as.factor(scallopData$Temperature)
```

```{r}
intR <- aov(RESP ~ Temperature*pH, data = scallopData)
summary(intR)
TukeyHSD(intR)
```

I get the error, Error in eval(expr, envir, enclos) : object 'RESP' not found Calls: ... eval -> -> model.frame.default -> eval -> eval

The solution is probably really obvious but I don't have that much experience with markdown yet.

1
Update the result of str(scallopData). Is RESP one of the variables? - Robert
The variables are pH and Temperature, RESP is what we've observed so they are the values. The str() gives: 'data.frame': 16 obs. of 18 variables: $ pH : Factor w/ 2 levels "7.7","8.2": 2 2 2 2 1 1 1 1 1 1 ... $ Temperature : Factor w/ 2 levels "25","29": 1 1 1 1 1 1 1 1 2 2 ... $ RESP : num -0.886 NA -0.895 -0.209 -0.313 ... Plus some more but they are not relevant to what I'm currently trying to do - Thije Zuidewind
Your second chunk is not receiving the data. Many possibilities: if you have other chunks, maybe you are deleting/removing the previous objects; your packages are updated? - Robert
Yes I updated my packages a few weeks ago. It could be that the objects are deleted but I wouldn't know why. I tried putting all the code in one chunk and it still couldn't find the object. - Thije Zuidewind

1 Answers

0
votes

your first chunk is fine. for the second one you need to load the packages you used before calling them in your syntax:

{r} library(anova) library(tukeyhsd) intR <- aov(RESP ~ Temperature*pH, data = scallopData) summary(intR) TukeyHSD(intR)