Skip to contents

Reads a synchronized .R history without executing it, asking a model or recovering pending writes. In "r" format the original Peter statements become comments and their recorded R stays executable. In "peter" format calls stay active and recorded R becomes comments, so it is not executed a second time. User R and comments keep their source order.

Usage

gptr_export(file, to, format = c("r", "peter"))

Arguments

file

An existing .R document with fresh recorded blocks.

to

A new .R path in an existing directory. Existing paths are never replaced.

format

"r" (default) or "peter".

Value

Invisibly, the normalized destination path.

Details

Only bare or symbol-assigned literal Peter calls and Peter-only native pipelines are admitted. Distinct statements sharing a line (including semicolon-separated statements), mixed pipelines, nested or computed calls, pending writes, missing or edited blocks, secret markers and interpolated-input hashes are refused. Raw exports also refuse ordinary code that uses a removed session handle. The Peter format retains such ordinary references, since its calls remain active. Feedback follows each pipeline operand when calls end on separate lines and only its pipe operator or a comment follows the closing call. Feedback follows the next operand's indentation (at most 74 characters); other layouts keep feedback after the complete statement. Peter calls already show their prompts, so only raw R adds prompt comments. Long raw prompt comments wrap at eighty characters. Strip the recorded-prompt prefix from the first line and the two-character comment prefix from continuations, then join without separators to recover the complete escaped R string literal. A Peter-only pipeline on one line keeps grouped feedback after the statement. Call source is never reformatted.

A completed-turn identity and matching source hashes establish a recorded snapshot, not verified execution or a complete session. Ordinary console input and record = FALSE effects cannot be reconstructed. External files, objects and package versions must still be supplied. Remaining user code may use gptr or perform network and filesystem operations. Captured #> output is limited to twelve lines per block and eighty characters per line; outputs are comments. Encoding, line endings and the final newline follow the input file. A UTF-8 byte order mark is preserved; source that exported file with source(to, encoding = "UTF-8-BOM").

Examples

input = tempfile(fileext = ".R")
output = tempfile(fileext = ".R")
writeLines(c("x = 1", "# Keep ordinary code and comments.", "y = x + 1"), input)
gptr_export(input, output)
readLines(output)
#> [1] "# Exported recorded R and ordinary source; not executed or validated." 
#> [2] "# Earlier console input and unrecorded tool effects are not recovered."
#> [3] "# Review code, external inputs and package versions before running."   
#> [4] ""                                                                      
#> [5] "x = 1"                                                                 
#> [6] "# Keep ordinary code and comments."                                    
#> [7] "y = x + 1"                                                             
unlink(c(input, output))