Comments (6)
Example. This call:
reprex({
x <- 1:4
y <- 2:5
x + y
})
gives rise to this:
x <- 1:4
y <- 2:5
x + y
#> [1] 3 5 7 9
Code that started out evenly indented is no longer so. Maybe I could be more respectful of whitespace when turning expression input into strings? But it would be much easier if there was a way to just re-indent.
from reprex.
Perhaps a job for formatR::tidy_source()
.
from reprex.
Fixed in 96f065a.
from reprex.
I think just using format()
on the quoted expression would work fine actually, no need for the extra dependency. FWIW it would be nice if reprex()
also accepted a pre-formatted string directly, like you get from clipr::read_clip()
.
ex <- quote({
x <- 1:4
y <- 2:5
x + y
})
cat(as.character(ex), sep = "\n")
#> {
#> x <- 1:4
#> y <- 2:5
#> x + y
cat(format(ex), sep = "\n")
#> {
#> x <- 1:4
#> y <- 2:5
#> x + y
#> }
from reprex.
reopening so I remember to try what you say @jimhester
from reprex.
OK yes format()
is not perfect, but it's better than nothing. formatR is a suggested package (which is already true via the knitr dependency anyway). If formatR is not available, then format()
is applied to the expression, once it has been captured as a character vector.
Here's how it does with a well-formatted expression. reprex()
call (example from above):
reprex({
x <- 1:4
y <- 2:5
x + y
})
Output:
x <- 1:4
y <- 2:5
x + y
#> [1] 3 5 7 9
And an expression with more pathological formatting. reprex()
call:
reprex({
x <- 1:10
for (i in x) {
print(i)
}
x
})
Output:
x <- 1:10
for (i in x) {
print(i)
}
#> [1] 1
#> [1] 2
#> [1] 3
#> [1] 4
#> [1] 5
#> [1] 6
#> [1] 7
#> [1] 8
#> [1] 9
#> [1] 10
x
#> [1] 1 2 3 4 5 6 7 8 9 10
from reprex.
Related Issues (20)
- Warning that R appears to crash when it does not HOT 1
- Thoughts about talking about reprexes HOT 1
- Error in xfun::normalize_path() : unused argument (resolve_symlink = FALSE) HOT 2
- reprex:::reprex_addin() on posit cloud does not show the preview HOT 1
- Take advantage of some backtrace improvements HOT 3
- Running in non-interactive mode using the `input` argument seems to use an existing `<input>_reprex.R` HOT 2
- Reprex v2.0.2 does not print all columns of bench::mark() HOT 1
- Upkeep for reprex
- Reprex skipping some statements (these should cause an error) HOT 2
- Add wd panel to Rstudio Addins Menu HOT 1
- Error in `reprex_render_impl()` HOT 3
- Unable to generate a reprex due to possibly clipboard or file connection issue HOT 2
- Question: Does `{reprex}` support MS Teams? HOT 4
- Error in reprex_render_impl() HOT 1
- Don't show the full backtrace HOT 1
- Output when following documentation instructions does not match expected result HOT 2
- Release reprex 2.1.0
- Enhance `would_clobber()` with more help getting rid of the offending file
- Error in read_xml.raw(res) : Start tag expected, '<' not found [4] HOT 4
- Warning exists when `reprex(... style = FALSE)` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reprex.