[R] Controlling font size on code chunk outputs using Knitr

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu Jan 30 17:57:39 CET 2014


This sounds like a classic "you need to write a custom CSS file" problem... Which is off-topic here, so is homework for you.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On January 30, 2014 8:34:32 AM PST, Jeff Johnson <mrjefftoyou at gmail.com> wrote:
>Hi Yihui,
>
>The package I have installed is "knitr". To generate the HTML, I run
>Knit
>HTML from within R Studio version .98.490 (there's an icon to initiate
>it.
>
>Here's a simple example:
>showcode <- FALSE
>commentchar <- NA
>
>You can load this data as 'mydf'...
>dput(mydf)
>structure(list(PERSONPROFILE_POS = "DV", PARTY_ID = 95252415L,
>    PERSON_FIRST_NAME = "Julie", PERSON_LAST_NAME = "herlastname",
>PERSON_MIDDLE_NAME = NA_character_,
> PARTY_NUMBER = 49229698L, ACCOUNT_NUMBER = 104205066L, ABILITEC_LINK =
>254555555695,
>    ADDRESS1 = "332 SE SOME RD", ADDRESS2 = NA_character_,
> ADDRESS3 = NA_character_, ADDRESS4 = NA_character_, CITY = "SOMECITY",
>    COUNTY = "SOMECOUNTY", STATE = "OR", PROVINCE = NA_character_,
>    POSTAL_CODE = "97111-1111", COUNTRY = "US", PRIMARY_PER_TYPE = "N",
>  SELLTOADDR_LOS = "DV", LOCATION_ID = 6222438L, SELLTOADDR_SOS = "DV",
>    PARTY_SITE_ID = 7292226L, PRIMARYPHONE_CPOS = "DV",
>CONTACT_POINT_ID_PCP = 62243903L,
>    CONTACT_POINT_PURPOSE_PCP = "PERSONAL", PHONE_LINE_TYPE = "GEN",
>    PRIMARY_FLAG_PCP = "Y", PHONE_COUNTRY_CODE = NA_integer_,
>  PHONE_AREA_CODE = "244", PHONE_NUMBER = "2444444", EMAIL_CPOS = "DV",
>    CONTACT_POINT_ID_ECP = 62222202L, CONTACT_POINT_PURPOSE_ECP =
>NA_character_,
>    PRIMARY_FLAG_ECP = "Y", EMAIL_ADDRESS = "someemail at yahoo.com",
>    BB_PARTY_ID = NA, VALID_COUNTRY = TRUE, VALID_USSTATE = TRUE,
>    POSTAL_PATTERN = "99999-9999", VALID_USPP = TRUE, FULL_PHONE =
>"2442444444",
>    FULL_PHONE_PATTERN = "NA9999999999", FNAME_PATTERN = "AAAAA",
>    FNAME_LENGTH = 5L, FNAME_TOKEN_COUNT = 1L, LNAME_LENGTH = 4L,
>    LNAME_PATTERN = "AAAA", MNAME_LENGTH = 2L, MNAME_PATTERN =
>NA_character_,
>    MNAME_TOKEN_COUNT = 1L, LNAME_TOKEN_COUNT = 1L, EMAIL_LENGTH = 19L,
>    VALID_EMAIL = TRUE), .Names = c("PERSONPROFILE_POS", "PARTY_ID",
>"PERSON_FIRST_NAME", "PERSON_LAST_NAME", "PERSON_MIDDLE_NAME",
>"PARTY_NUMBER", "ACCOUNT_NUMBER", "ABILITEC_LINK", "ADDRESS1",
>"ADDRESS2", "ADDRESS3", "ADDRESS4", "CITY", "COUNTY", "STATE",
>"PROVINCE", "POSTAL_CODE", "COUNTRY", "PRIMARY_PER_TYPE",
>"SELLTOADDR_LOS",
>"LOCATION_ID", "SELLTOADDR_SOS", "PARTY_SITE_ID", "PRIMARYPHONE_CPOS",
>"CONTACT_POINT_ID_PCP", "CONTACT_POINT_PURPOSE_PCP", "PHONE_LINE_TYPE",
>"PRIMARY_FLAG_PCP", "PHONE_COUNTRY_CODE", "PHONE_AREA_CODE",
>"PHONE_NUMBER", "EMAIL_CPOS", "CONTACT_POINT_ID_ECP",
>"CONTACT_POINT_PURPOSE_ECP",
>"PRIMARY_FLAG_ECP", "EMAIL_ADDRESS", "BB_PARTY_ID", "VALID_COUNTRY",
>"VALID_USSTATE", "POSTAL_PATTERN", "VALID_USPP", "FULL_PHONE",
>"FULL_PHONE_PATTERN", "FNAME_PATTERN", "FNAME_LENGTH",
>"FNAME_TOKEN_COUNT",
>"LNAME_LENGTH", "LNAME_PATTERN", "MNAME_LENGTH", "MNAME_PATTERN",
>"MNAME_TOKEN_COUNT", "LNAME_TOKEN_COUNT", "EMAIL_LENGTH", "VALID_EMAIL"
>), row.names = 1L, class = "data.frame")
>
>You can load that dataset, then:
>Print the column names
>```{r, echo=showcode, comment=commentchar}
>colnames(mydf)
>```
>The resulting font is a couple of points larger than I'd like. I'd like
>to
>be able to control this either globally or at the code chunk level.
>
>Thanks for your help with this!
>
>
>On Wed, Jan 29, 2014 at 5:57 PM, Yihui Xie <xie at yihui.name> wrote:
>
>> Please provide a minimal example -- are you using R Markdown or R
>> HTML? Both can produce HTML output:
>> http://yihui.name/knitr/demo/minimal/
>>
>> Regards,
>> Yihui
>> --
>> Yihui Xie <xieyihui at gmail.com>
>> Web: http://yihui.name
>>
>>
>> On Wed, Jan 29, 2014 at 10:49 AM, Jeff Johnson
><mrjefftoyou at gmail.com>
>> wrote:
>> > Hi there,
>> > I'm currently using knitr to generate an html file, however the
>output of
>> > my code is in a font size that's larger than I desire. I've been
>looking
>> > through various options for controlling the font size of the code
>> results,
>> > such as the knitr manual, opts_chunk, and latex.
>> >
>> > The actual code itself is not being outputted as desired (I set
>> echo=FALSE
>> > intentionally). However, I wish to make the results of executing
>the
>> code a
>> > couple of font sizes smaller. I'll likely wish to have all code
>output
>> > chunks be smaller, so a global setting is fine, though I would also
>> > appreciate understanding how to control it at the chunk level as
>well.
>> >
>> > Does any one have a recommendation on how to do this? Lots of
>discussion
>> on
>> > Google, but I don't see any tangible results. I'm still pretty new
>to R
>> > however.
>> >
>> > Thanks in advance.
>> > --
>> > Jeff
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > 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.
>>




More information about the R-help mailing list