Madhav pandey
Madhav pandey

Reputation: 361

Getting error while creating R markdown PDF report

I am getting an error while creating a PDF report out of R markdown file. Below is the snippet of the error:

   Error in --dayBikeData <- read.csv("D:\\Madhav\\Study\\MSIS\\PredictiveLearning\\Week-1\\Homework\\Bike-Sharing-Dataset\\day.csv") : 
  object 'dayBikeData' not found
Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval
Execution halted

I have this object -dayBikeData in the session but still it is giving the error don't know how to proceed on this.

Code for fetching the data from the csv file:

```{r}

dayBikeData <- read.csv("D:\\Madhav\\Study\\MSIS\\PredictiveLearning
                        \\Week-1\\Homework\\Bike-Sharing-Dataset\\day.csv")

# Performs each of the operation asked in the question
basicOperations <- function(inputData){
  lenData <- length(inputData)
  avg <- round(mean(inputData, na.rm = TRUE), digits = 2) # mean calculation
  standardDeviation <- round(sd(inputData), digits = 2) # Standard deviation
  sem <- round(standardDeviation/sqrt(lenData), digits = 2)
  # Formula for CI is mean - error where error is 
  error = round(qnorm(0.975)*standardDeviation/sqrt(lenData), digits = 2)
  lower_ci <- avg - error
  upper_ci <- avg + error

  # resultList <- list(obs = lenData, mean = avg, standarDeviation = sd,
  #                    standardMeanError= sem, lowerCI = lower_ci, upperCI = upper_ci

  resultList <- c(lenData, avg, standardDeviation, sem,lower_ci,upper_ci)
  print(resultList)
}

#Calculations for the Year Wise Data
# dData2011 <- dayBikeData[dayBikeData$yr==0,]
# dData2012 <- dayBikeData[dayBikeData$yr==1,]
dData2011ResultSet <- basicOperations(dayBikeData[dayBikeData$yr==0,]$cnt)
dData2012ResultSet <- basicOperations(dayBikeData[dayBikeData$yr==1,]$cnt)

#Calculations for the Holiday Wise Data
# dDataHoliady_0 <- dayBikeData[dayBikeData$holiday ==0,]
# dDataHoliady_1 <- dayBikeData[dayBikeData$holiday ==1,]
dDataHoliady0ResultSet <- basicOperations(dayBikeData[dayBikeData$holiday ==0,]$cnt)
dDataHoliady1ResultSet <- basicOperations(dayBikeData[dayBikeData$holiday ==1,]$cnt)

#Calculations for the WorkingDay Wise Data

# dDataWorkingDay_0 <- dayBikeData[dayBikeData$workingday ==0,]
# dDataWorkingDay_1 <- dayBikeData[dayBikeData$workingday ==1,]
dDataWorkingDay0ResultSet <- basicOperations(dayBikeData[dayBikeData$workingday ==0,]$cnt)
dDataWorkingDay1ResultSet <- basicOperations(dayBikeData[dayBikeData$workingday ==1,]$cnt)


#Calculations for the Temperature wise data

avgTemp <- mean(dayBikeData$temp, na.rm = TRUE)
dDataTempGreaterEq  <- dayBikeData[dayBikeData$temp >= avgTemp,]
dDataTempLess <- dayBikeData[dayBikeData$temp < avgTemp,]
dDataTempGreaterEqResultSet <- basicOperations(dDataTempGreaterEq$cnt)
dDataTempLessResultSet <- basicOperations(dDataTempLess$cnt)

#Calculations for the Weather wise data
# dDataWeather_1 <- dayBikeData[dayBikeData$weathersit ==1,]
# dDataWeather_2 <- dayBikeData[dayBikeData$weathersit ==2,]
# dDataWeather_3 <- dayBikeData[dayBikeData$weathersit ==3,]
dDataWeather1ResultSet <- basicOperations(dayBikeData[dayBikeData$weathersit ==1,]$cnt)
dDataWeather2ResultSet <- basicOperations(dayBikeData[dayBikeData$weathersit ==2,]$cnt)
dDataWeather3ResultSet <- basicOperations(dayBikeData[dayBikeData$weathersit ==3,]$cnt)

#Calculations for the Season wise data
# dDataSeason_1 <- dayBikeData[dayBikeData$season ==1,]
# dDataSeason_2 <- dayBikeData[dayBikeData$season ==2,]
# dDataSeason_3 <- dayBikeData[dayBikeData$season ==3,]
# dDataSeason_4 <- dayBikeData[dayBikeData$season ==4,]
dDataSeason1ResultSet <- basicOperations(dayBikeData[dayBikeData$season ==1,]$cnt)
dDataSeason2ResultSet <- basicOperations(dayBikeData[dayBikeData$season ==2,]$cnt)
dDataSeason3ResultSet <- basicOperations(dayBikeData[dayBikeData$season ==3,]$cnt)
dDataSeason4ResultSet <- basicOperations(dayBikeData[dayBikeData$season ==4,]$cnt)



#Constrcut a row wise data
resultData <- rbind(dData2011ResultSet, dData2012ResultSet, dDataHoliady0ResultSet,
                    dDataHoliady1ResultSet,dDataWorkingDay0ResultSet, 
                    dDataWorkingDay1ResultSet,dDataTempGreaterEqResultSet,
                    dDataTempLessResultSet, dDataWeather1ResultSet, 
                    dDataWeather2ResultSet, dDataWeather3ResultSet,dDataSeason1ResultSet, 
                    dDataSeason2ResultSet, dDataSeason3ResultSet,dDataSeason4ResultSet)
colnames(resultData) <- c("N","Mean","SD" , "SEM","Lower_CI", "UPPER_CI")


rownames(resultData) <- c("Year-0", "Year-1", "Holiday-0", "Holiday-1", "WorkingDay-0", 
                          "WorkingDay-1","Temperature >=","Temperature <", "Weather-1",
                          "Weather-2","Weather-3","Season-1","Season-2", "Season-3", 
                          "Season-4")

df.resultData <- as.data.frame(resultData)
df.resultData["Value"] <- NA
df.resultData$Value <- c(2011, 2012, 0,1, 0,1,1, 0, 1,2,3,1,2,3,4)

df.resultData = df.resultData[,c(7,1,2,3,4,5,6)]
library(knitr)
# print(xtable(df.resultData), type = "latex")
kable(df.resultData, format = "markdown")
write.csv(df.resultData, file = "D:\\X\\Study\\MSIS\\PredictiveLearning\\OutputResult.csv")

Upvotes: 2

Views: 134

Answers (2)

Mike Wise
Mike Wise

Reputation: 22807

I downloaded your dataset from UCI Machine Learning Repository, saved your markdown in a new folder, adjusted the filenames by deleting the paths, ran it, and it worked fine.

So I maybe your session is corrupt, or the paths are wrong, or something. Try what I did and it should work.

Proof:

enter image description here

Upvotes: 0

asachet
asachet

Reputation: 6921

Your file path is wrong... There is a new line and lots of spaces in the middle of it.

> "D:\\Madhav\\Study\\MSIS\\PredictiveLearning
+                         \\Week-1\\Homework\\Bike-Sharing-Dataset\\day.csv"
[1] "D:\\Madhav\\Study\\MSIS\\PredictiveLearning\n                        \\Week-1\\Homework\\Bike-Sharing-Dataset\\day.csv"

So the file is not getting read properly and hence the object is not available in the knitr session.

Upvotes: 2

Related Questions