Would this work in general? Say I have a document with figures, special
equations, text, and tables. The text and tables are relatively easy. The
figures would need a conversion from pixels to lines, and the equations maybe
printed out, counted as a figure, and then added to the line count. It would
also be tricky if a title line was at 32 point font and the text at 12, and the
more complex the formatting the harder to deal with rows as related to page
size.
Thankfully I do not think I will have to do this, so the question is for
theoretical interest on my part (at least for now).
Tim
-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Jeff Newmiller
via R-help
Sent: Saturday, December 2, 2023 11:46 AM
To: r-help at r-project.org
Subject: Re: [R] adding "Page X of XX" to PDFs
[External Email]
One of the most fundamental characteristics of R programming is the use of data
frames of column vectors, and one of the very first challenges I had as a
then-Perl-programmer was coming to grips with the fact that unknown-length CSV
files would be read completely into memory as rows and once the entire CSV was
in memory it would be transposed into column vectors. I was resistant to this
philosophy at first, but the advantages in computation speed and simplicity
eventually won me over.
I would say that if you want to know how many pages you are going to produce
with R, then you are going to have to count them before you create them.
Building a dataframe that describes (in terms of parameters to be passed to a
page-generating function in each row) what you are going to put on each page
before you actually print it can make this pre-counting problem trivial, and the
code that does the printing is likely to be more modular and testable as well.
On December 1, 2023 12:53:25 PM PST, Dennis Fisher <fisher at
plessthan.com> wrote:>OS X
>R 4.3.1
>
>Colleagues
>
>I often create multipage PDFs [pdf()] in which the text "Page X"
appears in the margin. These PDFs are created automatically using a massive R
script.
>
>One of my clients requested that I change this to:
> Page X of XX
>where XX is the total number of pages.
>
>I don't know the number of expected pages so I can't think of any
clever way to do this. I suppose that I could create the PDF, find out the
number of pages, then have a second pass in which the R script was fed the
number of pages. However, there is one disadvantage to this -- the original PDF
contains a timestamp on each page -- the new version would have a different
timestamp -- so I would prefer to not use this approach.
>
>Has anyone thought of some terribly clever way to solve this problem?
>
>Dennis
>
>Dennis Fisher MD
>P < (The "P Less Than" Company)
>Phone / Fax: 1-866-PLessThan (1-866-753-7784)
>http://www.plessthan.com/
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
--
Sent from my phone. Please excuse my brevity.
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.