knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

hijread

The goal of hijread is to facilitate the conversion from dates in the standard Gregorian calendar to Islamic dates following the Hijri calendar. The package's functions tap into the API of https://aladhan.com/islamic-calendar-api in order to carry out the conversion.

Installation

You can install the development version of hijread from GitHub with:

# install.packages("devtools")
devtools::install_github("Luka-Vasilj/hijread")

Example

Below, we show the code required to convert a Gregorian date to a Hijri date, as well as obtaining the names of the day of the week and Hijri month in Arabic. Note that dates passed to the functions must be strings in the dd-mm-yyyy format:

library(hijread)

x <- "12-12-2021"
hijdate(x)
hijday(x)
hijmonth(x)

The above functions can also be passed to the dplyr mutate() function in order to convert an entire set of dates, however, this must be mediated by the rowwise() function. Below, we create a dataset with randomized dates from the beginning of the Islamic calendar until the end of 2021. Then, we use the mutate() function to create a new column containing the corresponding Hijri dates.

library(dplyr)
library(stringi)

#creating randomized dates
a <- as.character(sample(1:30, 20, replace = T))
b <- as.character(sample(1:12, 20, replace = T))
c <- as.character(sample(623:2021, 20, replace = T))

#making date format uniform
ds <- as.data.frame(cbind(a, b, c)) %>%
  mutate(a = ifelse(stri_length(a) < 2, paste0("0", a), a),
         b = ifelse(stri_length(b) < 2, paste0("0", b), b),
         c = ifelse(stri_length(c) < 2, paste0("000", c), 
                    ifelse(stri_length(c) < 3, paste0("00", c),
                           ifelse(stri_length(c) < 4, paste0("0", c), c))))
ds$dated <- as.character(paste(ds$a, ds$b, ds$c, sep = "-"))


#attempting to use function on dataset
ds <- ds %>%
  rowwise() %>%
  mutate(hijri = hijdate(dated))

ds %>%
  select(dated, hijri) %>%
  head(10)

The potential use cases extend to more easily tracking and visualizing consumption, crime, and donation patterns in the Muslim world with reference to the Islamic calendar. Due to the nature of the Islamic calendar - it being a lunar calendar - the timing of certain events takes place at differing times every year according to the Gregorian calendar. For example, donations and food purchases increase drastically during the holy month of Ramadan, a multi-year pattern more easily identifiable if mapped against Islamic months, rather than Gregorian.



Luka-Vasilj/hijRead documentation built on Jan. 1, 2022, 12:53 p.m.