openair icon indicating copy to clipboard operation
openair copied to clipboard

Under the Open air package, is it possible to convert calendar plots, that show air pollution levels over the month, into ics/iCalendar files?

Open sanajanaparmar opened this issue 1 year ago • 3 comments

Feature request

Under the Open air package, is it possible to convert calendar plots, that show air pollution levels over the month, into ics/iCalendar files?

sanajanaparmar avatar Jan 29 '24 14:01 sanajanaparmar

Hello!

Could I please ask what your use-case is for this?

Writing ics files using R is not something I've ever done (or, to be honest, seen done!) using R, but a quick Google shows there's at least one R package for doing this:

https://cran.r-project.org/web/packages/calendar/index.html

Best, Jack

jack-davison avatar Jan 30 '24 09:01 jack-davison

I've written up some example code that runs calendarPlot(), pulls out the data, and writes the .ics files.

This sort of thing is very much out of scope for {openair} to do natively, but I hope you'll be able to usefully adapt what I've written below.


# install.packages("calendar")
# install.packages("openair")

library(openair)
library(calendar)

dir.create("caltest")
setwd("caltest")

# make calendar plot
cal_obj <- calendarPlot(mydata, "nox", year = 2000, month = 1)

# get data
cal_data <- cal_obj$data

# drop "missing" values
cal_data <- cal_data[!is.na(cal_data$date), ]

# format dates
cal_data$date <- lubridate::as_datetime(cal_data$date)

# make calendar events
events <-
  purrr::map(
    .x = split(cal_data, cal_data$date),
    .f = ~ calendar::ic_event(
      start_time = .x$date,
      end_time = 24,
      summary = paste0("NOx concentration: ", .x$value)
    )
  )

# save calendar events
purrr::iwalk(.x = events,
             .f = ~ calendar::ic_write(ic = .x, file = paste0(.y, ".ics")))

jack-davison avatar Jan 30 '24 09:01 jack-davison

Hello Jack,

Thank you so much for your quick response. The way I was looking at this was, if people could download the ics file and super impose with their google calendars, then they would have high AQI days on their calendars.

Thank you so much for giving this a go, I really appreciate it.

Warm regards, Sanjana

From: Jack Davison @.> Sent: Tuesday, January 30, 2024 4:37 AM To: davidcarslaw/openair @.> Cc: Sanjana Parmar @.>; Author @.> Subject: Re: [davidcarslaw/openair] Under the Open air package, is it possible to convert calendar plots, that show air pollution levels over the month, into ics/iCalendar files? (Issue #377)

Hello!

Could I please ask what your use-case is for this?

Writing ics files using R is not something I've ever done (or, to be honest, seen done!) using R, but a quick Google shows there's at least one R package for doing this:

https://cran.r-project.org/web/packages/calendar/index.html

Best, Jack

— Reply to this email directly, view it on GitHubhttps://github.com/davidcarslaw/openair/issues/377#issuecomment-1916431460, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BFV5QZZREHOOPI2TXTHHL23YRC5KZAVCNFSM6AAAAABCPRESFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJWGQZTCNBWGA. You are receiving this because you authored the thread.Message ID: @.***>

sanajanaparmar avatar Jan 30 '24 15:01 sanajanaparmar