Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running in non-interactive mode using the input argument seems to use an existing <input>_reprex.R #435

Closed
krlmlr opened this issue Mar 1, 2023 · 2 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@krlmlr
Copy link
Member

krlmlr commented Mar 1, 2023

Running reprex::reprex(input = "test.R") twice gives unexpected results if the input is changed between runs -- the second run still uses the "old" input.

I love meta-reprexes (and the fact that this works as expected)! 😍

# First time works
writeLines("42", "test.R")
reprex::reprex(input = "test.R")
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> ✔ Preparing reprex as `.R` file:
#>   'test_reprex.R'
#> ℹ Rendering reprex...
#> ✔ Writing reprex file:
#>   '/private/var/folders/dj/yhk9rkx97wn_ykqtnmk18xvc0000gn/T/RtmpYvuL1M/reprex-11815295ed36c-odd-tuna/test_reprex.md'
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
writeLines(readLines("test_reprex.md"))
#> ``` r
#> 42
#> #> [1] 42
#> ```
#> 
#> <sup>Created on 2023-03-01 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>

# Second time fails silently
writeLines("43", "test.R")
reprex::reprex(input = "test.R")
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
writeLines(readLines("test_reprex.md"))
#> ``` r
#> 42
#> #> [1] 42
#> ```
#> 
#> <sup>Created on 2023-03-01 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>

# Need to unlink to make it work
unlink("test_reprex.R")
reprex::reprex(input = "test.R")
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> ✔ Preparing reprex as `.R` file:
#>   'test_reprex.R'
#> ℹ Rendering reprex...
#> ✔ Writing reprex file:
#>   '/private/var/folders/dj/yhk9rkx97wn_ykqtnmk18xvc0000gn/T/RtmpYvuL1M/reprex-11815295ed36c-odd-tuna/test_reprex.md'
writeLines(readLines("test_reprex.md"))
#> ``` r
#> 43
#> #> [1] 43
#> ```
#> 
#> <sup>Created on 2023-03-01 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>

Created on 2023-03-01 with reprex v2.0.2

@jennybc jennybc added the bug an unexpected problem or unintended behavior label Mar 1, 2023
@jennybc
Copy link
Member

jennybc commented Jan 11, 2024

I think the behaviour is correct, i.e. not overwriting a file without getting permission, which is not possible in the non-interactive setting.

But I've made some changes to better explain what the user is seeing.

writeLines("42", "test.R")
reprex::reprex(input = "test.R")
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> ✔ Preparing reprex as `.R` file:
#>   'test_reprex.R'
#> ℹ Rendering reprex...
#> ✔ Writing reprex file:
#>   '/private/tmp/RtmpAruNqK/reprex-327160ae53b-soot-cub/test_reprex.md'
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
writeLines(readLines("test_reprex.md"))
#> ``` r
#> 42
#> #> [1] 42
#> ```
#> 
#> <sup>Created on 2024-01-10 with [reprex v2.0.2.9000](https://reprex.tidyverse.org)</sup>

writeLines("43", "test.R")
reprex::reprex(input = "test.R")
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> ! Oops, file already exists:
#>   'test_reprex.R'
#> ! Cancelling to avoid overwriting a file.
writeLines(readLines("test_reprex.md"))
#> ``` r
#> 42
#> #> [1] 42
#> ```
#> 
#> <sup>Created on 2024-01-10 with [reprex v2.0.2.9000](https://reprex.tidyverse.org)</sup>

unlink("test_reprex.R")
reprex::reprex(input = "test.R")
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> ✔ Preparing reprex as `.R` file:
#>   'test_reprex.R'
#> ℹ Rendering reprex...
#> ✔ Writing reprex file:
#>   '/private/tmp/RtmpAruNqK/reprex-327160ae53b-soot-cub/test_reprex.md'
writeLines(readLines("test_reprex.md"))
#> ``` r
#> 43
#> #> [1] 43
#> ```
#> 
#> <sup>Created on 2024-01-10 with [reprex v2.0.2.9000](https://reprex.tidyverse.org)</sup>

Created on 2024-01-10 with reprex v2.0.2.9000

@krlmlr
Copy link
Member Author

krlmlr commented Jan 13, 2024

Thanks, great! Should we also print a code that helps to get rid of the existing file? Should we offer deleting the file in an interactive session?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants