0

I am trying to knit my rmarkdown file to .html, however rstudio freezes when I reach certain computation-heavy commands like difftime a distHaverstine.

trips_2 <- trips_1 %>% 
   mutate(
     weekday = wday(started_at, label = T, abbr = F),
     month = month(started_at, label = T, abbr =F),
     week = strftime(started_at, format = "%V"),
     day = day(started_at),
     start_hour = hour(started_at),
     trip_length = as.numeric(difftime(ended_at, started_at,units = "secs"))

or

may_to_october_behavior <- trips_w_stations %>% 
  filter(month == 'May'|
           month == 'June'|
           month == 'July'|
           month == 'August'|
           month == 'September'|
           month == 'October') %>% 
  rowwise() %>% 
  mutate(trip_distance = distHaversine(c(start_lng, start_lat), c(end_lng, end_lat), 
                                       r=6378137)) %>% 
  filter(trip_distance > 0) %>% 
  group_by(customer_type, bike_type) %>% 
  summarize(mean_trip_length = mean(trip_length),
            mean_distance_travelled_m = mean(trip_distance),
            ride_count = n_distinct(ride_id)) %>% 
  mutate(avg_mph = (mean_distance_travelled_m/mean_trip_length)*2.2369)

Does anyone have any tips on how to solve this problem? My computer runs on Win10 and remains pretty beefy, which leads me to believe the issue may have to do with rstudio specifically.

In an attempt to lower the demand on the program, I have gone back and removed any dataframes that might clutter the environment, but even with the bare minimum data in my environment, I'm getting the same freeze issue.

Many thanks for any advice.

Phil
  • 7,287
  • 3
  • 36
  • 66
  • How are you executing the rendering operation? And does the error occur with even simpler code? Like `a <- 1; a+ 3`? – wibeasley Jan 13 '23 at 19:55
  • I have successfully knit simpler code without any issues. To render, I'm using the "knit" button on Rstudio and selecting the "knit to .html" option. – Pat Tarantino Jan 13 '23 at 21:57
  • In that case, build up the simple code until it breaks, then edit your response above and state which line breaks it for knitr (and verify that it still runs in regular R, without knitr). Also, please read and incorporate elements from [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269/1082435). Especially the aspects of using `dput()` for the input. – wibeasley Jan 14 '23 at 06:22

0 Answers0