{"id":20706442,"url":"https://github.com/pythoncoderunicorn/rlist","last_synced_at":"2026-03-09T17:47:31.834Z","repository":{"id":79731752,"uuid":"591120188","full_name":"PythonCoderUnicorn/rlist","owner":"PythonCoderUnicorn","description":"a repo for showing the rlist package","archived":false,"fork":false,"pushed_at":"2023-01-20T04:02:12.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-17T20:24:15.107Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"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/PythonCoderUnicorn.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-20T00:41:40.000Z","updated_at":"2023-01-20T00:41:40.000Z","dependencies_parsed_at":"2023-03-12T09:07:55.599Z","dependency_job_id":null,"html_url":"https://github.com/PythonCoderUnicorn/rlist","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/PythonCoderUnicorn%2Frlist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCoderUnicorn%2Frlist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCoderUnicorn%2Frlist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCoderUnicorn%2Frlist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PythonCoderUnicorn","download_url":"https://codeload.github.com/PythonCoderUnicorn/rlist/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242974027,"owners_count":20215256,"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-11-17T01:23:13.874Z","updated_at":"2025-12-06T17:02:23.567Z","avatar_url":"https://github.com/PythonCoderUnicorn.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# rlist\n\na repo for showing the {rlist} package, the information is from the rlist guide documentation. \n\n- rlist package imports jsonlite package to read/write JSON data.\n- rlist can handle YAML files\n\n## JSON data\n\n```\njs = '[\n    {\"name\": \"Apple\", \"age\": 67},\n    {\"name\": \"Windows\", \"age\": 78},\n    {\"name\": \"Linux\", \"age\": 44}\n  ]'\n\nstr( list.parse(js, \"json\") )\n```\n\nPrints\n```\nList of 3\n $ :List of 2\n  ..$ name: chr \"Apple\"\n  ..$ age : int 67\n $ :List of 2\n  ..$ name: chr \"Windows\"\n  ..$ age : int 78\n $ :List of 2\n  ..$ name: chr \"Linux\"\n  ..$ age : int 44\n```\n\n## YAML data\n\n```\nyam = \"\np1:\n  name: Apple\n  age: 167\np2:\n  name: Windows\n  age: 89\np3:\n  name: Linux\n  age: 56\n\"\n\nparsed_yaml = list.parse(yam, \"yaml\") \nparsed_yaml\n```\n\nPrints\n```\n$p1\n$p1$name\n[1] \"Apple\"\n\n$p1$age\n[1] 167\n\n(truncated)\n```\n\n\n## `list.load()` \u0026 `list.save()`\n\nthis looks at file extension and determines which loader to use\n\n```\nj = \"https://renkun-ken.github.io/rlist-tutorial/data/sample.json\"\n\nsmall_json = list.load(file= j, type = 'json')\n```\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n---\n\n### Mapping a JSON file\n\n```\nj = \"https://renkun-ken.github.io/rlist-tutorial/data/sample.json\"\n\nsmall_json = list.load(file= j, type = 'json')\n\nstr(small_json)\n```\n\nPrints \n```\nList of 3\n $ :List of 4\n  ..$ Name     : chr \"Ken\"\n  ..$ Age      : int 24\n  ..$ Interests: chr [1:3] \"reading\" \"music\" \"movies\"\n  ..$ Expertise:List of 3\n  .. ..$ R     : int 2\n  .. ..$ CSharp: int 4\n  .. ..$ Python: int 3\n\n(truncated)\n```\n\n\n### `lapply()` or `list.map()` JSON file\n\n```\n#--- method 1\n\nlapply(small_json, function(x) {\n  x$Name\n})\n\n#--- method 2\n\nlist.map(small_json, Name)\n```\n\nPrints\n```\n[[1]]\n[1] \"Ken\"\n\n[[2]]\n[1] \"James\"\n\n[[3]]\n[1] \"Penny\"\n```\n\nYou can use a function with list.map()\n\n```\nlist.map(small_json, sum( as.numeric(Expertise) )  )\n\nlist.map(small_json, list(Name = Name, range = range(as.numeric(Expertise))))\n```\n\n### list.map shorthand\n\nIn some cases we need to refer to the item itself, or its index in the list, or even its name. \nIn the expression:\n\n- `.` represents the item itself \n- `.i` represents its index\n- `.name` represents its name.\n\n```\nnums =  c(a=3, b=2, c=1)\n\nlist.map(nums, . + 1)\n```\n\nprints\n\n```\n$a\n[1] 4\n\n$b\n[1] 3\n\n$c\n[1] 2\n```\n\n\n## `list.mapv()`\n\nget a vector instead of a list returned\n\n```\nlist.mapv(small_json, Age)\n```\n\nPrints\n```\n[1] 24 25 24\n```\n\n\n### `list.maps()`\n\ncan use more than one list\n\n```\nL1 = list(p1= list(x=1, y=2), \n          p2= list(x=3, y=4), \n          p3= list(x=1, y=3) \n          )\n\nL2 = list(2, 3, 5)\n\nlist.maps(a$x * b + a$y, a= L1, b=L2)\n```\n\n\n\n\n\n\n\n## `list.select()`\n\nGet the Name and Expertise elements \n```\nlist.select(small_json, Name, Expertise)\n```\n\n\n## `list.iter()`\n\njust get a value\n\n```\nlist.iter(small_json, cat(Name, \":\", Age, \"\\n\"))\n```\n\nPrints\n```\nKen : 24 \nJames : 25 \nPenny : 24 \n```\n\n\n## Filter list\n\n`list.filter()` filters a list by an expression that returns TRUE or FALSE.\n\n```\nlist.filter(small_json, Age \u003e= 25)\n```\n\n# pipeR\n\nYou can use the pipe operator with a list\n\n```\nlibrary(pipeR)\n\nsmall_json %\u003e\u003e%\n  list.filter(Age \u003e= 25) %\u003e\u003e%\n  list.mapv(Name)\n```\n\n\n## `list.find()`\n\n```\npeople %\u003e\u003e%\n  list.find(Age \u003e= 25,n = 10) %\u003e\u003e%\n  list.mapv(Name)\n  \n# find index number location\nlist.findi(people, Age \u003e= 23, 2)\n```\n\n\n## `list.take()`\n\n```\nlist.take(5:10, 3)      # returns [1] 5 6 7\n```\n\n## `list.skip()`\n\n```\nlist.skip(1:10, 3)     # returns  [1]  4  5  6  7  8  9 10\n```\n\n## `list.count()`\n\n```\nlist.count(people, \"R\" %in% names(Expertise))\n```\n\n## `list.match()`\n\n```\ndata = list(a1= 3, a3= 7, c= 9)\n\nlist.match(data, \"a[3]\")      \n\n# returns \n$a3\n[1] 7\n```\n\n## `list.subset()`\n\n```\nsmall_json %\u003e\u003e% \n  subset(Age \u003e= 24, Name)\n  \n \nsmall_json %\u003e\u003e%\n  list.select(Name, Age) %\u003e\u003e%\n  list.stack\n```\n\n## `list.order()`\n\n```\nlist.order(small_json, Age)\n```\n\n## `list.sort()`\n\n```\nsmall_json %\u003e\u003e%\n  list.sort(Age) %\u003e\u003e%\n  list.select(Name, Age)\n```\n\n## `list.cases()`\n\n```\nlist.cases(small_json, Interests)\n```\n\nPrints\n```\n[1] \"movies\"  \"music\"   \"reading\" \"sports\" \n```\n\n\n## list.table\n\ntable() builds a contingency table of the counts at each combination of factor levels using cross-classifying factors. \nlist.table() is a wrapper that creates a table in which each dimension results from the values for an expression.\n\nThe function is very handy to serve as a counter. The following examples shows an easy way to know the remainders \nand the number of integers from 1 to 1000 when each is divided by 3.\n\n```\nlist.table(1:1000, . %% 3)\n```\n\nPrints\n```\n  0   1   2 \n333 334 333 \n```\n\n\n## `list.join()`\n\n```\nnewinfo = list(\n    list(Name=\"Ken\", Email=\"ken@xyz.com\"),\n    list(Name=\"Penny\", Email=\"penny@xyz.com\"),\n    list(Name=\"James\", Email=\"james@xyz.com\")\n    )\n\n\nlist.join(small_json, newinfo, Name)\n```\n\n\n## `list.search()`\n\n```\nlist.search(friends, . == \"Ken\")\n```\n\n## `list.parse()`\n\nconvert an object to a list, convert dataframe or a matrix to a list\n\n```\ndf = data.frame(\n  names = c(\"Linux\",\"Mac\",\"Windows\"),\n  age = c(58,57,48),\n  stringsAsFactors = F\n)\n\nlist.parse( df)\n```\n\n\n## `list.stack()`\n\nthe opposite of list.parse() on a dataframe, creates a dataframe\nTake the parsed yaml data and put in list.stack\n\n```\nlist.stack( parsed_yaml)\n\n\nlist.load(\"https://renkun-ken.github.io/rlist-tutorial/data/sample.json\") %\u003e\u003e%\n  list.select(Name, Age) %\u003e\u003e%\n  list.stack\n```\n\n\n\n## `list.flatten()`\n\n```{r}\nd = list(\n  list(\n    a= 10,\n    b= 20\n  ),\n  list(\n    c(c= 245,\n      d= list(w= 899,\n              h= 1788 ))\n  )\n)\n\nlist.flatten(d)\n\n```\n\n\n\n## `list.append()`\n\n```\nlist.append(list(a=100, b= 200, c= 300))\n```\n\n## `list.prepend()`\n\n```\nlist.prepend( list(alpha = 10, beta= 20, ceta= 30))\n```\n\n## `list.zip()`\n\n```{r}\nstr( list.zip(a= c(1,2,3), b= c(10,20,30)) )\n```\n\n\n\n## `list.rbind()`\n\n```{r}\nscores = list(\n  score1 = c(10,20,30),\n  score2 = c(100, 200, 300),\n  score3 = c(1e3, 2e3, 3e3)\n)\n\nlist.rbind( scores)\n```\n\nPrints\n\n```\n       [,1] [,2] [,3]\nscore1   10   20   30\nscore2  100  200  300\nscore3 1000 2000 3000\n```\n\n\n```{r}\nlist.cbind( scores )\n```\nPrints\n```\n     score1 score2 score3\n[1,]     10    100   1000\n[2,]     20    200   2000\n[3,]     30    300   3000\n```\n\n## list to matrix\n\n```{r}\nscores3 = list(\n  score1.1 = list(150, 250, 350),\n  score2.1 = list(1150, 2150, 3150),\n  period = list('one','two','three')\n)\n\nscores3_r = list.rbind( scores3)\nscores3_r\n```\n\nPrints\n```\n         [,1]  [,2]  [,3]   \nscore1.1 150   250   350    \nscore2.1 1150  2150  3150   \nperiod   \"one\" \"two\" \"three\"\n```\n\n\n## lambda\n\n```{r}\nx = list(\n  a= c(w= 10, d= 20 ),\n  b = c(w= 100, d= 200)\n)\n\nlist.map(x, sum(d))\n```\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythoncoderunicorn%2Frlist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpythoncoderunicorn%2Frlist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythoncoderunicorn%2Frlist/lists"}