Giter VIP home page Giter VIP logo

reprex.sh's Introduction

reprex.sh: poor man's reprex

reprex.sh is a bash script that creates a reprex from a shell script. It:

  • runs R given an R script (possibly from stdin)
  • outputs the R commands
  • outputs the output from R after comment # symbols

Requires: bash

Example

Given an R script file, buf.R that contains

library(terra)
v = vect("LINESTRING(0 85,1 85)") 
crs(v) = 'EPSG:4326'
v
(b = buffer(v, 10000))

run the script with

reprex.sh buf.R

to get the following output:

library(terra)
# terra 1.7.35
v = vect("LINESTRING(0 85,1 85)")
crs(v) = 'EPSG:4326'
v
#  class       : SpatVector
#  geometry    : lines
#  dimensions  : 1, 0  (geometries, attributes)
#  extent      : 0, 1, 85, 85  (xmin, xmax, ymin, ymax)
#  coord. ref. : lon/lat WGS 84 (EPSG:4326)
(b = buffer(v, 10000))
#  class       : SpatVector
#  geometry    : polygons
#  dimensions  : 1, 0  (geometries, attributes)
#  extent      : -1.027163, 2.027163, 84.91046, 85.08954  (xmin, xmax, ymin, ymax)
#  coord. ref. :

(example taken from here). With this reprex, anyone can see which R commands were run, and what output it generated, and try to reproduce it, by:

  • re-running it in R by copy-and-paste, because the R output follows # and is interpreted as comment
  • comparing the output thus obtained with the output shown in the reprex

Installation

Put the reprex.sh shell script somewhere in your search path. Make sure it has executable permissions, noted by the x in -rwxr-xr-x:

$ ls -la reprex.sh
-rwxr-xr-x 1 edzer edzer 107 Jun 14 13:10 reprex.sh

reprex.sh's People

Contributors

edzer avatar

Stargazers

 avatar Caleb Jenkins avatar Fernando Mayer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.