{"id":24590887,"url":"https://github.com/blmoore/pythonistr","last_synced_at":"2026-04-30T19:32:06.237Z","repository":{"id":152044614,"uuid":"91205107","full_name":"blmoore/pythonistr","owner":"blmoore","description":"Write more pythonic R","archived":false,"fork":false,"pushed_at":"2017-06-03T09:51:23.000Z","size":50,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T18:40:05.290Z","etag":null,"topics":["python","r","rstats"],"latest_commit_sha":null,"homepage":"http://blm.io/pythonistr","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/blmoore.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":"2017-05-13T21:58:44.000Z","updated_at":"2017-06-03T21:23:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"febbca06-8ab7-4831-90eb-0f7c14d03d70","html_url":"https://github.com/blmoore/pythonistr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/blmoore/pythonistr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blmoore%2Fpythonistr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blmoore%2Fpythonistr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blmoore%2Fpythonistr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blmoore%2Fpythonistr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blmoore","download_url":"https://codeload.github.com/blmoore/pythonistr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blmoore%2Fpythonistr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32475192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["python","r","rstats"],"created_at":"2025-01-24T09:26:42.530Z","updated_at":"2026-04-30T19:32:06.221Z","avatar_url":"https://github.com/blmoore.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"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)\n```\n\n# pythonistr\n\n[![travis_status](https://travis-ci.org/blmoore/pythonistr.svg?branch=master)](https://travis-ci.org/blmoore/pythonistr)\n[![codecov](https://codecov.io/gh/blmoore/pythonistr/branch/master/graph/badge.svg)](https://codecov.io/gh/blmoore/pythonistr)\n[![docs_badge](https://img.shields.io/badge/docs-latest-blue.svg)](http://blm.io/pythonistr)\n[![CRAN_badge](http://www.r-pkg.org/badges/version/pythonistr)](https://cran.r-project.org/package=pythonistry)\n\npythonistr brings over a few ideas from the python language into R.\n\n## Install\n\nInstall from github with:\n\n```{r, eval = FALSE}\ndevtools::install_github(\"blmoore/pythonistr\")\n```\n\n## Usage\n\n```{r load_pkg, echo=FALSE}\nlibrary(pythonistr)\n```\n\n### Shortcuts\n\nIn python, to instantiate a list of strings with minimal typing you could use:\n\n```{python}\nprint('i want a list of words'.split())\n```\n\npythonistr adds `separate` (or `s` for short):\n\n```{r}\ns(\"saves you typing and matching quotes\")\n```\n\n----------\n\nString and sub-string matching intent is clear in Python:\n```{python} \nif 'char' in 'character string':\n   print('Found!')\n```\n\npythonistr adds `%within%` as an alias for `grepl(pattern, string)`:\n\n```{r}\nif ('char' %within% 'character string')\n  print('Found!')\n```\n\n------\n\n### Python functions\n\nPython has a great context management system that closes file connections\nwhen they fall out of scope:\n\n```{python with_example, eval=FALSE}\nwith open('file.csv', 'r') as f:\n  for line in f:\n    print(line)\n```\n\nPythonistr adds a `with` method to connections which mirrors this behaviour:\n\n```{r with_r, eval=FALSE}\nfile_conn \u003c- file(\"file.csv\", \"r\")\nwith(file_conn, {\n  while (TRUE) {\n    line \u003c- readLines(file_conn, n = 1)\n    if (length(line) == 0) {\n      break\n    }\n    print(line)\n  }\n})\n\nisOpen(file_conn) # FALSE (well, error)\n```\n\nEven better, there's some support for line-by-line processing. In Python you \nmight write:\n\n```{python iterate_stop, eval=FALSE}\nwith open('log.txt', 'r') as l:\n  for line in l:\n    print line\n    if 'stop' in line:\n      break\n```\n\nWith pythonistr, you could write this as:\n\n```{r iterate_stop_r, eval=FALSE}\nlog \u003c- file('log.txt', 'r')\nwith(log,\n  by_line(log, \n    print, # function to apply to each line\n    function(l) grepl(\"stop\", l) # stop when true\n  )\n)\n```\n\nAnything executed by `by_line` is currently only useful for its side-effects.\n\n\n### Aliases\n\nIf you regularly switch between R and Python you might be used to \ngetting tripped up by `length` vs. `len` but this isn't the only\nexample. For example: which language prefers `reversed` over `rev`? Which \nimplements `sorted` as well as `sort`? \n\npythonistr includes a few shortcuts to lower the context \nswitching overhead, though it's probably a bad idea to rely \non these in normal R programming.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblmoore%2Fpythonistr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblmoore%2Fpythonistr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblmoore%2Fpythonistr/lists"}