How to import ical .ics file in R

给你一囗甜甜゛ 提交于 2019-12-05 07:58:31

Here's an example

x <- readLines("https://www.kicksonfire.com/releases/?ical=1&tribe_display=list", warn = FALSE)
stopifnot(!any(grepl("^\\s+", x))) # disregarding value fields that have linefeeds for the sake of simplicity 
keyval <- do.call(rbind, regmatches(x, regexpr(":", x, fixed = TRUE), invert = TRUE))
keyval <- keyval[which.max(keyval[,1]=="BEGIN" & keyval[,2]=="VEVENT"):tail(which(keyval[,1]=="END" & keyval[,2]=="VEVENT"), 1),]
keyval <- cbind.data.frame(keyval, id=cumsum(keyval[,1]=="BEGIN" & keyval[,2]=="VEVENT"))
df <- reshape(keyval, timevar="1", idvar="id", direction = "wide")
head(df[,c(3,4,9)])
#    2.DTSTART;VALUE=DATE 2.DTEND;VALUE=DATE                              2.SUMMARY
# 1              20170422           20170423         Air Jordan 11 Low GS Blue Moon
# 14             20170422           20170423     Air Jordan 5 Premium Pure Platinum
# 27             20170427           20170428              Nike Air VaporMax Asphalt
# 40             20170427           20170428                 Nike Air VaporMax Oreo
# 53             20170427           20170428  Nike WMNS Air VaporMax White Ice Blue
# 66             20170427           20170428 wings+horns x adidas NMD R2 Light Grey

A simpler and more robust option available now is the calendar package on CRAN (documentation here). Importing from an ICS file to a data frame takes one line of code, and creating new events then exporting to a new ICS file is also straightforward.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!