Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6941883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:56:35+00:00 2026-05-27T12:56:35+00:00

I analyze measurements from many cities (hundreds), and need to create separate reports per

  • 0

I analyze measurements from many cities (hundreds), and need to create separate reports per city (in Adobe pdf-format).

My process is like this:

  1. First RStudio to prepare the data to be shown, saved in X.Rda.
  2. In X.Rnw (RStudio) I read X.Rda, select one city, and produce the tables and plots.
  3. In RStudio I press “Compile PDF” and the city-report X.pdf is produced.
  4. I go to step 2, choose another city, and so on.

This is very tedious, and looks perfect for a for-loop per city, but how can it be done?

Thank you r-contributors!

/Chris

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:56:36+00:00Added an answer on May 27, 2026 at 12:56 pm

    You can use something like a for loop with a global variable changing, which controls which city you want to weave into the report; see the other post Run Sweave or knitr with objects from existing R session

    The code will be like (suppose cities is a character vector, and I use the knitr package as an example because you can specify the filename of the output):

    for (city in cities) {
       knit('city_template.Rnw', output = paste('report_', city, '.tex', sep = ''))
    }
    

    Inside city_template.Rnw, you have a chunk like

    <<do-my-job>>=
    make_plot(city, ...)
    whatever(city, ...)
    @
    

    Then you will get a series of tex files named by the cities, and the rest of your job is to compile them to PDF (not possible for RStudio to compile multiple tex files, AFAIK, but it is trivial to do it in command line or in R with texi2dvi()).

    There is one thing you need to be careful — you have to use a different figure prefix (the option fig.path) for each output file, otherwise different cities can override each other’s figure output. In knitr, this can be done by like this:

    <<setup, echo=FALSE>>=
    opts_chunk$set(fig.path = paste('my-prefix-', city, sep = ''))
    @
    

    I believe this should be safe to produce many reports with a loop.

    BTW, you can certainly achieve the same goal with Sweave; perhaps you will know why I developed knitr later (this is off-topic, so I won’t expand here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to analyze an SQL Server stored procedure from .NET code to retrieve
I need to analyze a users' post and categorize it. For example: I have
For a project, I need to analyze the differences in development time between two
I need to analyze some C++ source files in order to generate some very
I'm trying to analyze a bunch of search terms, so many that individually they
After I REPAIR OPTIMIZE ANALYZE OR CHECK a table, do I need to FLUSH
I want to analyze a piece of document and build an ontology from it.
I need to analyze 1 TB+ of web access logs, and in particular I
I'm trying to analyze my database from Androids adb shell in OS X terminal,
I were asked to analyze an assembly code, which was generated from following c++

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.