reprex icon indicating copy to clipboard operation
reprex copied to clipboard

Feature request: Scrub username from reprex

Open szimmer opened this issue 11 months ago • 0 comments

Many times when using packages like here or generating a file with tempfile, the file path includes the username. I'd like this to be scrubbed from a reprex. This can be accessed using Sys.getenv("username") and then replaced with ***, {username}, or something like that. I currently do this manually. Here's an example of where I've manually replaced my actual username with {username}:

library(foreign)

datafile <- tempfile()
codefile <- tempfile()
write.foreign(head(iris), datafile, codefile, package="SAS", dataname="iris_ds", validvarname="V7")
#> Some variable names were abbreviated or otherwise altered.
writeLines(readLines(datafile))
#> 5.1,3.5,1.4,0.2,1
#> 4.9,3,1.4,0.2,1
#> 4.7,3.2,1.3,0.2,1
#> 4.6,3.1,1.5,0.2,1
#> 5,3.6,1.4,0.2,1
#> 5.4,3.9,1.7,0.4,1
writeLines(readLines(codefile))
#> * Written by R;
#> *  write.foreign(head(iris), datafile, codefile, package = "SAS",  ;
#> 
#> PROC FORMAT;
#> value Species 
#>      1 = "setosa" 
#>      2 = "versicolor" 
#>      3 = "virginica" 
#> ;
#> 
#> DATA  iris_ds ;
#> INFILE  "C:\Users\{username}\AppData\Local\Temp\RtmpeAHqom\file5ff446a5df2" 
#>      DSD 
#>      LRECL= 21 ;
#> INPUT
#>  Sepal_Length
#>  Sepal_Width
#>  Petal_Length
#>  Petal_Width
#>  Species
#> ;
#> LABEL  Sepal_Length = "Sepal.Length" ;
#> LABEL  Sepal_Width = "Sepal.Width" ;
#> LABEL  Petal_Length = "Petal.Length" ;
#> LABEL  Petal_Width = "Petal.Width" ;
#> FORMAT Species Species. ;
#> RUN;
unlink(datafile)
unlink(codefile)

Created on 2025-01-28 with reprex v2.1.1

szimmer avatar Jan 28 '25 17:01 szimmer