{"id":13782522,"url":"https://github.com/quartzbio/r-coverage-patch","last_synced_at":"2025-05-11T15:32:34.677Z","repository":{"id":91043662,"uuid":"28040998","full_name":"quartzbio/r-coverage-patch","owner":"quartzbio","description":"Patches to add code coverage support in the R interpreter.","archived":true,"fork":false,"pushed_at":"2014-12-16T16:37:09.000Z","size":528,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-17T17:43:23.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quartzbio.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2014-12-15T14:50:30.000Z","updated_at":"2023-03-23T14:52:48.000Z","dependencies_parsed_at":"2023-02-28T07:31:33.420Z","dependency_job_id":null,"html_url":"https://github.com/quartzbio/r-coverage-patch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartzbio%2Fr-coverage-patch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartzbio%2Fr-coverage-patch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartzbio%2Fr-coverage-patch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartzbio%2Fr-coverage-patch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quartzbio","download_url":"https://codeload.github.com/quartzbio/r-coverage-patch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253588753,"owners_count":21932319,"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","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":[],"created_at":"2024-08-03T18:01:38.470Z","updated_at":"2025-05-11T15:32:34.271Z","avatar_url":"https://github.com/quartzbio.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"r-coverage-patch\n================\n\nPatches to add code coverage support in the R interpreter.\n\n## Overview\nThis repository contains patches of the [R](http://www.r-project.org/) interpreter source code to add [code coverage](http://en.wikipedia.org/wiki/Code_coverage) support. \nIt allows to know which exact lines of source code were exercized/hit/covered while running some piece of code (usually a test suite).\nThe easiest way to test it is using our docker container: https://github.com/quartzbio/r-coverage-docker\n\n## Installation\nAs stated above, you can just use the docker container.\nTo patch it manually:\n 1. choose the appropriate patch corresponding to the version of the R interpreter you are going to use.\n 1. get the source code of the R version (download and untar)\n 2. patch the source code (patch)\n 3. configure the source directory (./configure)\n 4. compile and install (make; make install)\n\nThe project is organized in sudirectories per supported R version, e.g. r302 for R version 3.0.2.\nThe above steps are somewhat automated using a Makefile (you need probably GNU make).\nFor example, to download, untar, patch, configure, make and install R-3.0.2:\n```bash\ngit clone https://github.com/quartzbio/r-coverage-patch.git\ncd r-coverage-patch/r302/\n# download, untar and patch\nmake apply_production_patch \n# install in ./local/\nmake install \n# Or install in a custom place\nmake install PREFIX=/whatever/\n\n# run it\n./local/bin/R\n\n```\n\n\n\n## Implementation\nI added a condition in the internal C function **getSrcref()**, that records the line numbers if the code\ncoverage is started (via Rcov_start()).\nThe overhead should be minimal since for a given file, subsequent covered lines will be stored\nin constant time. \nI use a hashed env to store the occurrences by file.\n\nI added two entry points in the utils package (**Rcov_start()** and **Rcov_stop()**)\n\n### viewing the main patched file: eval.c\nFor convenience (Caution: it can be outdated), I included the main patched file in the repo, \nyou can view it here: https://github.com/quartzbio/r-coverage-patch/blob/master/r302/patched_files/eval.c\n\n## Usage \n(see also https://github.com/quartzbio/r-coverage-docker#usage).\n\nStart the patched R interpreter, then:\n```r\nlibrary(devtools)\npkg  \u003c- download.packages('testthat', '.', repos = \"http://stat.ethz.ch/CRAN\")\nuntar(pkg[1, 2])\n\nRcov_start()\ntest('testthat')\nres \u003c- as.list(Rcov_stop())\nprint(res)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquartzbio%2Fr-coverage-patch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquartzbio%2Fr-coverage-patch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquartzbio%2Fr-coverage-patch/lists"}