How to import .ics file into R

I would like to import . ics file in R, however, when I try to do it like ...

sneak_cal <- read.delim("iCal-TribeEvents.ics", sep = ":", header=FALSE, stringsAsFactors = FALSE, strip.white = TRUE, na.strings = "")

... I am finishing the separation of the site's character strings (belonging to the field X-ORIGINAL-URLor UID), which is undesirable

ie httpsand//www.kicksonfire.com

The ultimate goal is to get the data in a neat format, where each row is one VEVENT, which, I think, will be represented unique UIDwithout loss of information (for example, URL)

Is there any other approach that is recommended, for example, pre-defining the fields expected as a key and matching the value or empty space with this key? Since the file .icshas the same expected fields every time, it seems to make sense to use these fields as a template for reading in the data, but I cannot figure out how to do this.

+4
source share
1 answer

Here is 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
+5
source

Source: https://habr.com/ru/post/1675455/


All Articles