{"id":16703806,"url":"https://github.com/leeper/lookfor","last_synced_at":"2025-04-10T05:02:27.234Z","repository":{"id":28402538,"uuid":"31916879","full_name":"leeper/lookfor","owner":"leeper","description":"R port of Stata's lookfor command","archived":false,"fork":false,"pushed_at":"2022-10-31T17:08:55.000Z","size":48,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T06:11:52.358Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leeper.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-09T19:00:50.000Z","updated_at":"2022-11-08T07:03:52.000Z","dependencies_parsed_at":"2023-01-14T08:45:07.243Z","dependency_job_id":null,"html_url":"https://github.com/leeper/lookfor","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/leeper%2Flookfor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeper%2Flookfor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeper%2Flookfor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeper%2Flookfor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leeper","download_url":"https://codeload.github.com/leeper/lookfor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161270,"owners_count":21057554,"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-10-12T19:09:44.097Z","updated_at":"2025-04-10T05:02:27.144Z","avatar_url":"https://github.com/leeper.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lookfor: Find what you're looking for #\n\n**lookfor** is an R port of Stata's `lookfor` command, which helps you find stuff you're looking for inside a dataset (e.g., variables, variable values, variable labels, etc.).\n\n## Package Installation ##\n\n[![CRAN](http://www.r-pkg.org/badges/version/lookfor)](http://cran.r-project.org/web/packages/lookfor/)\n![Downloads](http://cranlogs.r-pkg.org/badges/lookfor)\n[![Travis-CI Build Status](https://travis-ci.org/leeper/lookfor.png?branch=master)](https://travis-ci.org/leeper/lookfor)\n[![Codecov](http://www.r-pkg.org/badges/version/lookfor)](http://cran.r-project.org/web/packages/lookfor/)\n[![codecov.io](http://codecov.io/github/leeper/lookfor/coverage.svg?branch=master)](http://codecov.io/github/leeper/lookfor?branch=master)\n[![Project Status: Wip - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus.org/#wip)\n\nThe latest development version on GitHub can be installed using **devtools**:\n\n```R\nif(!require(\"devtools\")){\n    install.packages(\"devtools\")\n    library(\"devtools\")\n}\ninstall_github(\"leeper/lookfor\")\n```\n\n## Examples ##\n\nStata's `lookfor` command searches variables and variable labels for an exact matching text string:\n\n```\n. webuse auto\n(1978 Automobile Data)\n\n. lookfor weight\n\n              storage   display    value\nvariable name   type    format     label      variable label\n---------------------------------------------------------------------\nweight          int     %8.0gc                Weight (lbs.)\n\n. lookfor ft\n\n              storage   display    value\nvariable name   type    format     label      variable label\n---------------------------------------------------------------------\ntrunk           int     %8.0g                 Trunk space (cu. ft.)\nturn            int     %8.0g                 Turn Circle (ft.)\n```\n\nThis is helpful and something easily replicated by searching within the `names` attribute of a data.frame. But R allows multiple objects to be present at one time, meaning that it would be time consuming to `grep` the names of all data.frames that might be active in memory at any given point in time. Similarly, those R objects are also themselves named, have numerous other attributes (`rownames`, `colnames`, `levels`, `class`, etc.), and might be stored within lists or environments. While the `lookfor` command in Stata is helpful, it's actually solving a relatively simple problem. Porting `lookfor` to R requires a much more robust solution for searching many different features of potentially numerous data objects stored in various parts of the R environment.\n\nThe major weakness of Stata's `lookfor` command is that it relies only on a plain text, exact matching search algorithm. This makes it difficult to search for variables or labels that match a pattern (e.g., a pattern that might easily be described by a regular expression). As a result, the R port uses `grepl` to find matches, meaning that regular expressions are used by default when trying to find something and arguments can be passed via `...` to control the behavior of `grepl` (e.g., setting `fixed=TRUE` will match an exact string, and `perl=TRUE` will use Perl-style regular expressions).\n\n### Look in a data.frame ###\n\n```{r, results=\"hide\"}\noptions(width = 100)\n```\n\nA basic use case is to search for an observation or a variable within a dataset.\n\n```{r}\nlibrary(\"lookfor\")\ndata(USArrests)\n\n# look for observation\nlookin(USArrests, \"Alaska\")\n\n# look for variable\nlookin(USArrests, \"Assault\")\n```\n\n\n### Look in an environment ###\n\nRelatedly, it is possible to search for objects within an environment (and values or attributes within those objects).\n\n```{r, results=\"hold\"}\nx \u003c- new.env()\nx$mtcars \u003c- mtcars\nx$cars \u003c- letters[1:10]\nx$cards \u003c- 1:5\nlookin(x, \"car\")\n```\n\n\n### Look in a list ###\n\nAnd the same can be applied to a potentially deeply nested list.\n\n```{r}\nm \u003c- lm(mpg ~ cyl, data = mtcars)\nlookin(m, \"mpg\")\n```\n\n\n### Look everywhere ###\n\nLastly, the `lookfor` command can be used to look anywhere (within `.GlobalEnv`, the R search path, objects within objects on the search path, loaded namespaces, etc.).\n\n```{r}\nlookfor(\"package\")\n```\n\n### Look using regular expression ###\n\nAs noted above, Stata's `lookfor` command can only match exact/partial character strings. The R port by uses `grepl`, meaning that regular expressions are supported by default, thus allowing for complex pattern matching.\n\n```{r}\ndata(mtcars)\n\n# Look for car names containing letters and numbers (anywhere)\nlookfor(\"[[:alpha:]]+ [[:digit:]]\")\n\n# Look for car names containing letters and numbers (in mtcars)\nlookin(mtcars, \"[[:alpha:]]+ [[:digit:]]\")\n```\n\n### Search `comment()` values ###\n\nR's `comment()` function is an underutilized feature that allows users to attach hidden comments to R objects. This is intended (see `? comment`) for helping to annotate R objects with relevant metadata. The value of `comment()` for an object is `NULL` unless it has been set, in which case it is usually a character vector of length 1 (or possibly greater). `lookfor` searches `comment()` values automatically, allowing you to make better use of these annotations.\n\n```{r}\nm1 \u003c- lm(mpg ~ cyl, data = mtcars)\ncomment(m1) \u003c- \"model using continuous cylinder\"\n\nm2 \u003c- lm(mpg ~ factor(cyl), data = mtcars)\ncomment(m2) \u003c- \"model using factor of cylinder\"\n\nlookfor(\"model using\", fixed = TRUE)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleeper%2Flookfor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleeper%2Flookfor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleeper%2Flookfor/lists"}