{"id":29540024,"url":"https://github.com/jonmcalder/refactor","last_synced_at":"2025-09-15T08:24:56.262Z","repository":{"id":80359012,"uuid":"66887343","full_name":"jonmcalder/refactor","owner":"jonmcalder","description":":bookmark: Better factor handling for R","archived":false,"fork":false,"pushed_at":"2020-11-13T15:11:32.000Z","size":263,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-06-13T00:52:05.143Z","etag":null,"topics":["factor","package","r"],"latest_commit_sha":null,"homepage":"https://jonmcalder.github.io/refactor/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonmcalder.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-29T23:08:07.000Z","updated_at":"2020-11-13T15:11:34.000Z","dependencies_parsed_at":"2023-03-12T10:51:14.051Z","dependency_job_id":null,"html_url":"https://github.com/jonmcalder/refactor","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jonmcalder/refactor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmcalder%2Frefactor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmcalder%2Frefactor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmcalder%2Frefactor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmcalder%2Frefactor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonmcalder","download_url":"https://codeload.github.com/jonmcalder/refactor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmcalder%2Frefactor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275227046,"owners_count":25427306,"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-09-15T02:00:09.272Z","response_time":75,"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":["factor","package","r"],"created_at":"2025-07-17T07:38:24.810Z","updated_at":"2025-09-15T08:24:56.210Z","avatar_url":"https://github.com/jonmcalder.png","language":"R","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"README-\"\n)\nlibrary(refactor, warn.conflicts = FALSE)\n```\n\n# refactor\n\n[![Project Status: Abandoned – Initial development has started, but there has not yet been a stable, usable release; the project has been abandoned and the author(s) do not intend on continuing development.](https://www.repostatus.org/badges/latest/abandoned.svg)](https://www.repostatus.org/#abandoned)\n[![Build Status](https://travis-ci.org/jonmcalder/refactor.svg?branch=master)](https://travis-ci.org/jonmcalder/refactor)\n[![codecov](https://codecov.io/gh/jonmcalder/refactor/branch/master/graph/badge.svg)](https://codecov.io/gh/jonmcalder/refactor)\n\n**refactor** is an R package which aims to provide better handling of factors. Though R does have a special data type for factors, it isn't always explicity catered for in commonly used R functions, which can lead to unexpected and undesirable outcomes (e.g. see this [Win-Vector blog post](http://www.win-vector.com/blog/2014/09/factors-are-not-first-class-citizens-in-r/)). This observation formed the inspiration for 're'-factor: which is essentially to 're'-visit functions likely to be used with factor data and where possible to wrap, extend or override them in order to better cater for factor data, or at the very least to provide warnings when the integrity of the data could be compromised by an operation.\n\n## Installation\n\nrefactor is not available on CRAN but you can easily install the latest development version from github using `devtools`:\n\n```r\n# install.packages(\"devtools\")\ndevtools::install_github(\"jonmcalder/refactor\")\n```\n\n## Overview\n\nBelow are a few examples to illustrate some scenarios in which refactor can improve on base R's handling of factors.\n\nPlease see the vignette for more details: `vignette(\"refactor\", package = \"refactor\")`\n\n#### Better factor creation with `cfactor()`\n\n- get warnings whenever provided factor levels don't fully match those present in the data\n\n```{r}\nstring \u003c- c(\"a\", \"b\", \"c\")\nfactor(string, levels = c(\"b\", \"c\", \"d\"))\ncfactor(string, levels = c(\"b\", \"c\", \"d\"))\n```\n\n- numerical sequences in strings are detected and utilized to obtain correct orderings for factor levels\n\n```{r}\nhard_to_detect \u003c- c(\"EUR 21 - EUR 22\", \"EUR 100 - 101\", \"EUR 1 - EUR 10\", \"EUR 11 - EUR 20\")\nfactor(hard_to_detect, ordered = TRUE)\ncfactor(hard_to_detect, ordered = TRUE)\n```\n\n#### Extension of the generic `cut` method to handle (discrete) integer data\n\n- generate 'natural' intervals for factors when using cut on integer vectors\n    - e.g. `[1,3], [4,6], [7,9]` as opposed to `(0.5, 3.5], (3.5, 6.5], (6.5, 9.5]`\n\n- label factor levels more intuitively\n    - e.g. `1-3, 4-6, 7-9` as opposed to `[1,3], [4,6], [7,9], or (0,3], (3,6], (6-9]`\n\n```{r}\nx_int \u003c- 1:9\ncut.default(x_int, breaks = 3)\ncut(x_int, breaks = 3)\n```    \n\n#### Extension of the generic `cut` method to handle (non-numeric) ordered data\n\n- `cut` usually requires numeric data, but refactor extends `cut` to handle other ordered data\n\n```{r}\nsome_letters \u003c- factor(c('d','e','f','a','b','c','g','h','i'), ordered = TRUE)\ncut(some_letters, breaks = c('a','c','f','i'), include.lowest = TRUE, ordered_result = TRUE)\n```\n\n## Contributions\n\nSuggestions and feedback are most welcome.  \n  \nFeel free to [open an issue](https://github.com/jonmcalder/refactor/issues) if you want to request a feature or report a bug, and make a pull request if you can contribute.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonmcalder%2Frefactor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonmcalder%2Frefactor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonmcalder%2Frefactor/lists"}