Skip to content

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

@pablo14

Description

@pablo14

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions