1
votes

I am trying to run frame_calendar for my univariate time series data in r. When I try to compute the calendar layout for the data frame, I am getting the following error.

Error in mutate_impl(.data, dots) : Evaluation error: object '72L' not found.

From similar threads, I see the evaluation error: object ' ' not found is usually for an object the users have input in the code. However, in my case, I am not referring to any '72L' in my code. And it is not in my data set as well. Can you please help me figure out how to fix this error? Any help is much appreciated.

Here is a part of my data.

Date_Time   Time    Date    Year    Month   Mdate   Day Hours_Time  Hourly_Counts
1/1/2015 0:00   0:00:00 2015-01-01  2015    January 1   Thursday    1   72
1/1/2015 1:00   1:00:00 2015-01-01  2015    January 1   Thursday    2   48
1/1/2015 2:00   2:00:00 2015-01-01  2015    January 1   Thursday    3   53
1/1/2015 3:00   3:00:00 2015-01-01  2015    January 1   Thursday    4   84
1/1/2015 4:00   4:00:00 2015-01-01  2015    January 1   Thursday    5   68

Here's my code.

newdata <- read.csv("D:/NEWDATA.csv")
attach(newdata)
View(newdata)

newdata[,3] <- as.Date(Date, origin = "1/1/2000")
attach(newdata)
View(newdata)


library(dplyr)
# compute the calendar layout for the data frame
calendar_df <- newdata %>%
  filter(Year == 2015) %>%
  frame_calendar(x = Time, y = Hourly_Counts, date = Date)
1
frame_calendar is from suggrants? And two side notes: 1) don't attach() your data frame, especially if you're going to use tidyverse functions (which use nonstandard evaluation). 2) you do have 72L in your data. It's the integer 72, which is the first value in newdata$Hourly_CountsDe Novo
Yes, then if you use base methods to mutate, you'll have to wrap it in with() or extract them explicitly (e.g., newdata$Date)De Novo
@DanHall yes, frame_calendar is from suggrants package. if i don't attach() data frame the first time after reading the data, as you suggested, then i get the error: > Error in as.Date(Date, origin = "1/1/2000") : object 'Date' not found. However, if I attach() the first time and omit the 2nd attach() I still get the > Error in mutate_impl(.data, dots) : Evaluation error: object '72L' not found. Also, I can see your point in the integer 72, i just don't understand why the calendar layout is searching for a specific data value. I apologize if this is too basic question.user4932167
@DanHall here is an edited version of my code. I have tried tibble() as an alternative to convert Date to a Date Class. newpm10 <- read.csv("D:/NEWDATA.csv") View(newdata) newdata <- as_tibble(newdata) newdate <- as.Date(Date, origin = "1/1/2000") View(newdate) newdata <- mutate(newdata, Date = newdate) View(newdata) library(dplyr) # compute the calendar layout for the data frame calendar_df <- newdata %>% filter(Year == 2015) %>% frame_calendar(x = Time, y = Hourly_Counts, date = Date) however it is still giving the same error. Thank you for your help.user4932167
The main source of your problem is that you used attach, which masked Hourly_Counts in the call to frame_calendar. See the answer below. To run it, make sure you start with a clean environment. You've run attach() multiple times, which means you're going to have to detach for each of those times.De Novo

1 Answers

0
votes

The main problem here is that when you attach() your data frame first you mask a number of objects that you need. Generally, don't use attach. If you want to work with an attached data set, use it inside a call to with, and certainly don't combine this with dplyr or other tidyverse functions.

With a clean environment (no data or namespaces attached), use dplyr methods throughout, like this. Other than not attaching, notice the two other changes to your code. (1) use mutate to set the Date column within the dplyr pipe. (2) x = Hours_Time, rather than Time. If you've previously run attach(new_data), do detach(new_data) first, UNTIL you have a clean environment. If you've run it multiple times, you're going to have to detach multiple times.

library(dplyr)
library(sugrrants)
new_data %>%
  mutate(Date = as.Date(Date, origin = "1/1/2000")) %>%
  frame_calendar(x = Hours_Time, y = Hourly_Counts, date = Date)
#       Date_Time    Time Year   Month Mdate      Day Hours_Time Hourly_Counts       Date
# 1 1/1/2015 0:00 0:00:00 2015 January     1 Thursday          1            72 2015-01-01
# 2 1/1/2015 1:00 1:00:00 2015 January     1 Thursday          2            48 2015-01-01
# 3 1/1/2015 2:00 2:00:00 2015 January     1 Thursday          3            53 2015-01-01
# 4 1/1/2015 3:00 3:00:00 2015 January     1 Thursday          4            84 2015-01-01
# 5 1/1/2015 4:00 4:00:00 2015 January     1 Thursday          5            68 2015-01-01
#   .Hours_Time .Hourly_Counts
# 1    1.454167      0.6833333
# 2    1.691667      0.0500000
# 3    1.929167      0.1819444
# 4    2.166667      1.0000000
# 5    2.404167      0.5777778

Data:

new_data <- read.table(text = "Date_Time   Time    Date    Year    Month   Mdate   Day Hours_Time  Hourly_Counts
'1/1/2015 0:00'   0:00:00 2015-01-01  2015    January 1   Thursday    1   72
                       '1/1/2015 1:00'   1:00:00 2015-01-01  2015    January 1   Thursday    2   48
                       '1/1/2015 2:00'   2:00:00 2015-01-01  2015    January 1   Thursday    3   53
                       '1/1/2015 3:00'   3:00:00 2015-01-01  2015    January 1   Thursday    4   84
                       '1/1/2015 4:00'   4:00:00 2015-01-01  2015    January 1   Thursday    5   68", header = TRUE, stringsAsFactors = FALSE)