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

width.cutoff doesn't work (problem in deparse function) #77

Closed
pablo14 opened this issue Feb 11, 2018 · 1 comment
Closed

width.cutoff doesn't work (problem in deparse function) #77

pablo14 opened this issue Feb 11, 2018 · 1 comment

Comments

@pablo14
Copy link

pablo14 commented Feb 11, 2018

Hi Yihui :)

EDIT: 2018-FEB-19: I did a hack who tries to fit the desired width, and works for many cases. Reference: #71.

I'm using formatR inside bookdown and I found an issue when creating the PDF. The maximum width doesn't work for the code (but it does for comments!)

Easily reproducible at formatR, copy the following lines (using minimum line width=56)

Input:

# Keeping all columns except the ones present in 'vars_to_remove' vector
heart_disease_2=select(heart_disease, -one_of(vars_to_remove))
aasd = select(daa, -one_of(holas), -one_of(holas), -one_of(holas))

Output:


# Keeping all columns except the ones present in
# 'vars_to_remove' vector
heart_disease_2 = select(heart_disease, -one_of(vars_to_remove))
aasd = select(daa, -one_of(holas), -one_of(holas), -one_of(holas))

Width line 3: 64
Width line 3: 66

So it didn't re adjust the with for the code.

Afer doing several test, I tracked the problem to what it seem its origin: base::deparse function.

Testing from your code:

text="# Keeping all columns except the ones present in 'vars_to_remove' vector
heart_disease_2 = select(heart_disease, -one_of(vars_to_remove))
aasd = select(daa, -one_of(holas), -one_of(holas), -one_of(holas))"

exprs = parse_only(text)

base::deparse(exprs, width)
[1] "expression(heart_disease_2 = select(heart_disease, -one_of(vars_to_remove)), "
[2] "    aasd = select(daa, -one_of(holas), -one_of(holas), -one_of(holas)))"  

If I try lower width, let's say 40, it adjust the 3rd line but the max len is 50...

I would have like to fix it myself, but I'm lack of ideas to debug deparse function... Any ideas?

Related to this case: https://stackoverflow.com/questions/20778635/formatr-width-cutoff-issue

Thanks!

@yihui yihui closed this as completed in 3064d8d Mar 17, 2021
@yihui
Copy link
Owner

yihui commented Mar 17, 2021

With #71 just merged, it seems it works okay for this particular case now:

> tidy_source(width.cutoff = I(56))

# Keeping all columns except the ones present in
# 'vars_to_remove' vector
heart_disease_2 = select(heart_disease,
    -one_of(vars_to_remove))
aasd = select(daa, -one_of(holas), -one_of(holas),
    -one_of(holas))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants