{"id":14067734,"url":"https://github.com/reconhub/aweek","last_synced_at":"2026-02-19T07:35:55.129Z","repository":{"id":53604552,"uuid":"172648833","full_name":"reconhub/aweek","owner":"reconhub","description":"Convert dates to arbitrary week definitions :calendar:","archived":false,"fork":false,"pushed_at":"2022-10-06T02:40:38.000Z","size":376,"stargazers_count":18,"open_issues_count":5,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-25T13:55:55.605Z","etag":null,"topics":["date-formatting","dates","epidemiology","r","r-package","timeseries","week"],"latest_commit_sha":null,"homepage":"https://www.repidemicsconsortium.org/aweek","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reconhub.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-26T06:07:45.000Z","updated_at":"2025-07-13T23:12:32.000Z","dependencies_parsed_at":"2023-01-19T07:45:52.910Z","dependency_job_id":null,"html_url":"https://github.com/reconhub/aweek","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/reconhub/aweek","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reconhub%2Faweek","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reconhub%2Faweek/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reconhub%2Faweek/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reconhub%2Faweek/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reconhub","download_url":"https://codeload.github.com/reconhub/aweek/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reconhub%2Faweek/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267798625,"owners_count":24145727,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["date-formatting","dates","epidemiology","r","r-package","timeseries","week"],"created_at":"2024-08-13T07:05:45.088Z","updated_at":"2026-02-19T07:35:55.100Z","avatar_url":"https://github.com/reconhub.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- badges: start --\u003e\n\n[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-ago/aweek)](https://cran.r-project.org/package=aweek) \n[![Codecov test coverage](https://codecov.io/gh/reconhub/aweek/branch/master/graph/badge.svg)](https://codecov.io/gh/reconhub/aweek?branch=master) \n[![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/aweek?color=ff69b4)](https://cran.r-project.org/package=aweek)\n[![DOI](https://zenodo.org/badge/172648833.svg)](https://zenodo.org/badge/latestdoi/172648833)\n[![R-CMD-check](https://github.com/zkamvar/aweek/workflows/R-CMD-check/badge.svg)](https://github.com/zkamvar/aweek/actions)\n\u003c!-- badges: end --\u003e\n\n# Welcome to the *aweek* package!\n\nThis package will convert dates to [US CDC\nepiweeks](https://wwwn.cdc.gov/nndss/document/MMWR_Week_overview.pdf),\n[isoweeks](https://en.wikipedia.org/wiki/ISO_week_date), and all others in\nbetween with minimal overhead. \n\n## Installing the package\n\nTo install the stable package version from CRAN, you can use\n\n```{r install, eval = FALSE}\ninstall.packages(\"aweek\")\n```\n\nTo benefit from the latest features and bug fixes, install the development,\n*github* version of the package using:\n\n```{r install2, eval = FALSE}\n# install.packages(\"remotes\")\nremotes::install_github(\"reconhub/aweek\")\n```\n\n# Main Features\n\n - `date2week()` converts dates to a week format (YYYY-Www-d) that can start on \n   any day. \n - `week2date()` / `as.Date()` does the backwards conversion from\n   (YYYY-Www(-d)) to a numeric date. \n - `get_aweek()` generates an aweek object from a week number\n - `get_date()` converts a week number to a date\n - `as.aweek()` converts dates, characters, and factors to aweek objects.\n - `factor_aweek()` creates an aggregated factor of weeks where the levels\n   contain all weeks within range.\n - Dependencies only on R itself.\n\n\u003c!-- --\u003e\n\n## Dates to weeks\n\n\nWith the *aweek* package, converting dates to weeks is simple. All you need to\nknow is what weekday represents the beginning of your week and a vector of \ndates.\n\n```{r epiweek}\n# generate dates\nset.seed(2019-02-26)\nonset \u003c- as.Date(\"2019-02-26\") + sort(sample(-6:7, 20, replace = TRUE))\n\n# load aweek\nlibrary(\"aweek\")\nset_week_start(\"Monday\") # set the default start of the week\n\nprint(onset)\ndate2week(onset) # convert dates to weeks\n```\n\nIf you want to override the default, you can use the `week_start` attribute of\n`date2week()`:\n\n\n```{r epiweek_options}\ndate2week(onset, week_start = 1) # ISO weeks starting on Monday (default)\ndate2week(onset, week_start = 7) # EPI week starting on Sunday\ndate2week(onset, week_start = 6) # EPI week starting on Saturday\nx \u003c- date2week(onset, week_start = \"sat\", floor_day = TRUE) # truncate to just the weeks\ntable(x)\ntable(week2date(x))\n```\n\n## Weeks to dates\n\nIf you have numeric weeks, you can rapidly convert to dates with `get_date()`.\nHere are all the dates for the first day of last 10 ISO weeks of 2015:\n\n```{r get_date}\nget_date(week = 44:53, year = 2015)\n\n# you can also use this to generate aweek objects\nget_aweek(week = 44:53, year = 2015)\n```\n\nIf you have weeks recorded from different data sets that start on different\ndays, you can account for that by using the `start` option. For example,\n2018-01-01 is a Monday, but 2018-W01-1 starting on a Sunday is 2017-12-31\n\n```{r different_starts}\nget_date(week = 1, year = 2018, day = 1, start = c(\"Sunday\", \"Monday\"))\n\n# get_aweek will align them to the default week_start\nget_aweek(week = 1, year = 2018, day = 1, start = c(\"Sunday\", \"Monday\"))\n```\n\n\n## Factors\n\nYou can also automatically calculate factor levels, which is useful in\ntabulating across weeks and including missing values. \n\n```{r show_factors}\nset.seed(2019-02-26)\nonset \u003c- as.Date(\"2019-02-26\") + sort(sample(-48:49, 20, replace = TRUE))\nx     \u003c- date2week(onset, week_start = \"sat\", factor = TRUE)\nx\ntable(x)\n```\n\n## Locales\n\nIt's also possible to specify the week_start in terms of the current locale, \nhowever it is important to be aware that code like this may not be portable.\n\n```{r locale_dates, error = TRUE}\n\n# workaround because of differing locale specifications\ngerman \u003c- if (grepl(\"darwin\", R.version$os)) \"de_DE.UTF-8\" else \"de_DE.utf8\"\nlct \u003c- Sys.getlocale(\"LC_TIME\")\nres \u003c- Sys.setlocale(\"LC_TIME\", german)\n\ndate2week(as.Date(\"2019-02-26\"), week_start = \"Sonntag\")\ndate2week(as.Date(\"2019-02-26\"), week_start = \"Sunday\")\n\nSys.setlocale(\"LC_TIME\", lct)\n\n```\n\n## Getting help online\n\nBug reports and feature requests should be posted on *github* using the\n[*issue*](https://github.com/reconhub/aweek/issues) system. All other questions\nshould be posted on the **RECON forum**: \u003cbr\u003e\n[https://www.repidemicsconsortium.org/forum/](https://www.repidemicsconsortium.org/forum/)\n\nContributions are welcome via **pull requests**.\n\nPlease note that this project is released with a [Contributor Code of\nConduct](CONDUCT.md). By participating in this project you agree to abide by\nits terms.\n\n## Similar Work\n\nThere are other packages that can define ISOweeks and/or epiweeks. However, the\nability to easily switch between day and week intervals is only available for\nthe ISOweek package and all of the packages above have dependencies that\nrequire compiled code.\n\n - [ISOweek](https://cran.r-project.org/package=ISOweek) converts dates to ISO\n   weeks as the \"%W\" and \"%u\" formats don't exist in windows\n - [lubridate](https://github.com/tidyverse/lubridate) performs general\n   datetime handling with some auxiliary functions that return the week or day\n   of the week. \n - [surveillance](https://surveillance.r-forge.r-project.org/) implements ISOWeekYear. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freconhub%2Faweek","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freconhub%2Faweek","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freconhub%2Faweek/lists"}