{"id":14068290,"url":"https://github.com/jeroenjanssens/rexpect","last_synced_at":"2025-03-21T14:31:28.294Z","repository":{"id":150228313,"uuid":"230439800","full_name":"jeroenjanssens/rexpect","owner":"jeroenjanssens","description":"Automate Interactive Applications in R","archived":false,"fork":false,"pushed_at":"2024-04-26T12:15:40.000Z","size":4237,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T02:12:05.823Z","etag":null,"topics":["automation","expect","rstats"],"latest_commit_sha":null,"homepage":"https://jeroenjanssens.github.io/rexpect/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeroenjanssens.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":"2019-12-27T12:26:22.000Z","updated_at":"2024-11-16T13:21:06.000Z","dependencies_parsed_at":"2024-08-13T07:13:57.929Z","dependency_job_id":"548d8c61-f59b-482c-b7d5-15bd354e4175","html_url":"https://github.com/jeroenjanssens/rexpect","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/jeroenjanssens%2Frexpect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeroenjanssens%2Frexpect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeroenjanssens%2Frexpect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeroenjanssens%2Frexpect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeroenjanssens","download_url":"https://codeload.github.com/jeroenjanssens/rexpect/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244815193,"owners_count":20514911,"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":["automation","expect","rstats"],"created_at":"2024-08-13T07:06:04.659Z","updated_at":"2025-03-21T14:31:27.612Z","avatar_url":"https://github.com/jeroenjanssens.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput:\n  github_document:\n    html_preview: true\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# rexpect \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"100px\" /\u003e\n\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://www.tidyverse.org/lifecycle/#stable)\n\n`rexpect` is an R package that allows you to automate interactions with programs that\nexpose a text terminal interface. The API is inspired by the original Expect tool by Don Libes.\n\n## Installation\n\nYou can install the development version from [GitHub](https://github.com/) with:\n\n```{r, eval = FALSE}\n# install.packages(\"remotes\")\nremotes::install_github(\"jeroenjanssens/rexpect\")\n```\n\n\n## Example\n\nLet's say we have a Python script that repeatedly asks for a number.\nWhen the user enters `sum`, the script prints the sum of all the numbers.\nThe script exits when the user presses `CTRL-C`. \nHere's the contents of _bin/sum.py_:\n\n```{verbatim, file = \"bin/sum.py\", lang = \"python\"}\n```\n\nWe can use `rexpect` to run this script and interact with it.\nLet's enter the numbers 7, 13, and 22 and see what the sum is:\n\n```{r}\nlibrary(rexpect)\n\nsession \u003c- spawn(\"bin/sum.py\", prompt = \"^(.*):$\")\nsend_lines(session, c(\"7\", \"13\", \"22\", \"sum\"), wait = TRUE)\n```\n\nUnder the hood, `rexpect` starts a tmux session using [tmuxr](https://jeroenjanssens.github.io/tmuxr):\n\n```{r}\nsession\n```\n\nWe can capture the output and extract the sum:\n\n```{r}\nprint(output \u003c- read_all(session))\nas.numeric(gsub(\"[^0-9.]\", \"\", output[length(output) - 1]))\n```\n\nWe've accomplished our goal, so let's exit:\n\n```{r}\nsend_lines(session, \"exit\")\nread_all(session)\n```\n\nOh that's right, we need to press `CTRL-C` to exit the script:\n\n```{r}\nsend_control_c(session)\n```\n\nThis was a rather simple example to demonstrate some of the capabilities of `rexpect`.\nThe session could have taken place inside a Docker container or over SSH. \nWe could also have recorded the session using [asciinema](https://asciinema.org/).\nHave a look at [the function reference](https://jeroenjanssens.github.io/rexpect/reference/) to learn more about what `rexpect` has to offer.\n\n## License\n\nThe `rexpect` package is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeroenjanssens%2Frexpect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeroenjanssens%2Frexpect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeroenjanssens%2Frexpect/lists"}