Re: [R] Help with knitr pkg

2018-07-19 Thread Bill Poling
Hi Rainer:

Thank you I will have a look at the link you provide.
As I mentioned,
“#opts_chunk$set(fig.path = "c:/WHP/Appeals/OutputPDFs/EX V1.pdf") <--I 
don't even understand what this does, poached it from one of the google sites I 
have been reviewing and tried to make it work?”

Hopefully your reference has an example I can follow, will let you know, cheers.

WHP


>>Not sure, if I get you right. Seems, that you use knitr:: and code
chunks without the necessary context?

Please have a look at 
https://rmarkdown.rstudio.com/<https://rmarkdown.rstudio.com/> to get a more
general understanding about using knitr within RMarkdown context.<<<<



From: Rainer Hurling 
Sent: Thursday, July 19, 2018 3:45 AM
To: Bill Poling 
Cc: r-help (r-help@r-project.org) 
Subject: Re: [R] Help with knitr pkg

Hi Bill,

Am 18.07.18 um 18:33 schrieb Bill Poling:
> Hi,
> I worked through this excellent tutorial:
> #Elegant regression results tables and plots in R: the finalfit package
> https://www.r-bloggers.com/elegant-regression-results-tables-and-plots-in-r-the-finalfit-package/<https://www.r-bloggers.com/elegant-regression-results-tables-and-plots-in-r-the-finalfit-package/>
>
>
>
> Now I am applying it to my own data.
>
> In the tutorial there is mention of:
>
> # Tables can be knitted to PDF, Word or html documents. We do this in
> # RStudio from a .Rmd document. Example chunk:
> # ```{r, echo = FALSE, results='asis'}
> # knitr::kable(example_table, row.names=FALSE,
> # align=c("l", "l", "r", "r", "r", "r"))
> # ```
>
> I am having a difficult time understanding how this works?
>
> I have read through the help:
>
> ?knitr
> #"This function takes an input file, extracts the R code in it according to a 
> list of patterns, evaluates the code and writes the output in another file.
> #It can also tangle R source code from the input document (purl() is a 
> wrapper to knit(..., tangle = TRUE)).
> #The knitr.purl.inline option can be used to also tangle the code of inline 
> expressions (disabled by default)."
>
> install.packages("knitr")
> library(knitr)
> ?knit
> ?stitch
> install.packages("stitch")#package 'stitch' is not available (for R version 
> 3.5.1)
> ?spin
> install.packages("spin") #package 'spin' is not available (for R version 
> 3.5.1)Warning in install.packages : Perhaps you meant 'SPIn' ?
>
> I have also looked at the github and knitr author's links
>
> https://github.com/yihui/knitr<https://github.com/yihui/knitr>
>
> https://yihui.name/knitr/demo/stitch/<https://yihui.name/knitr/demo/stitch/>
>
> https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.Rmd<https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.Rmd>
>
>
> If I understand this correctly I have to have a template already in place as 
> the input object, is that correct? How would I construct this it that is so?
>
> I also tried writing out directly to pdf and png with no success.
>
> #pdf("c:/WHP/Appeals/OutputPDFs/EX V1.pdf")
> #png("c:/WHP/Appeals/OutputPDFs/EX V1.png")
> #opts_chunk$set(fig.path = "c:/WHP/Appeals/OutputPDFs/EX V1.pdf") <--I 
> don't even understand what this does, poached it from one of the google sites 
> I have been reviewing and tried to make it work?
>
> #This is the script I would like the output placed in PDF
> explanatory = c("claimStatusId", "AgeCat", "PatientGender", "PayorID")
> dependent = "AppealOverturned" # Appeals Status
> appdf1DT2 %>%
> summary_factorlist(dependent, explanatory, p=TRUE, add_dependent_label=TRUE)
>
> #dev.off()
>
>
> str(appdf1DT2)
> # Classes 'data.table' and 'data.frame': 3983 obs. of 21 variables:
> # $ ClaimServiceID : Factor w/ 3983 levels "51318639","51318640",..: 1 2 4 3 
> 5 12 6 8 7 9 ...
> # $ LineNumber : Factor w/ 140 levels "1","2","3","4",..: 1 2 4 3 5 7 1 3 2 4 
> ...
> # $ claimStatusId : Factor w/ 2 levels "2","3": 2 2 2 2 2 1 1 1 1 1 ...
> # $ PatientGender : Factor w/ 3 levels "F","M","UNK": 2 2 2 2 2 1 1 1 1 1 ...
> # $ PayorID : Factor w/ 19 levels "000","234","239",..: 1 1 1 1 1 1 1 1 1 1 
> ...
> # $ AppealID : Factor w/ 512 levels "79765","116998",..: 1 1 1 1 1 2 2 2 2 2 
> ...
> # $ ZipCode : Factor w/ 223 levels "2155","3037",..: 72 72 72 72 72 102 102 
> 102 102 102 ...
> # $ EditID : Factor w/ 21 levels "","0","001X",..: 2 12 8 12 8 8 2 8

Re: [R] Help with knitr pkg

2018-07-19 Thread Thierry Onkelinx
Dear Bill,

It seems like you are looking at the wrong help files. The code in the
tutorial uses the package::function() syntax. So knitr::kable()
translates into use the function kable() from the knitr package. The
help file you are looking for is ?kable (when knitr is loaded) or
?knitr::kable (when knitr is not loaded).

Best regards,

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
AND FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkel...@inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be

///
To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey
///




2018-07-18 18:33 GMT+02:00 Bill Poling :
> Hi,
> I worked through this excellent tutorial:
> #Elegant regression results tables and plots in R: the finalfit package
> https://www.r-bloggers.com/elegant-regression-results-tables-and-plots-in-r-the-finalfit-package/
>
>
>
> Now I am applying it to my own data.
>
> In the tutorial there is mention of:
>
> # Tables can be knitted to PDF, Word or html documents. We do this in
> # RStudio from a .Rmd document. Example chunk:
> #   ```{r, echo = FALSE, results='asis'}
> # knitr::kable(example_table, row.names=FALSE,
> #  align=c("l", "l", "r", "r", "r", "r"))
> # ```
>
> I am having a difficult time understanding how this works?
>
> I have read through the help:
>
> ?knitr
> #"This function takes an input file, extracts the R code in it according to a 
> list of patterns, evaluates the code and writes the output in another file.
> #It can also tangle R source code from the input document (purl() is a 
> wrapper to knit(..., tangle = TRUE)).
> #The knitr.purl.inline option can be used to also tangle the code of inline 
> expressions (disabled by default)."
>
> install.packages("knitr")
> library(knitr)
> ?knit
> ?stitch
> install.packages("stitch")#package 'stitch' is not available (for R version 
> 3.5.1)
> ?spin
> install.packages("spin") #package 'spin' is not available (for R version 
> 3.5.1)Warning in install.packages :  Perhaps you meant 'SPIn' ?
>
> I have also looked at the github and knitr author's links
>
> https://github.com/yihui/knitr
>
> https://yihui.name/knitr/demo/stitch/
>
> https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.Rmd
>
>
> If I understand this correctly I have to have a template already in place as 
> the input object, is that correct? How would I construct this it that is so?
>
> I also tried writing out directly to pdf and png with no success.
>
> #pdf("c:/WHP/Appeals/OutputPDFs/EX V1.pdf")
> #png("c:/WHP/Appeals/OutputPDFs/EX V1.png")
> #opts_chunk$set(fig.path = "c:/WHP/Appeals/OutputPDFs/EX V1.pdf") <--I 
> don't even understand what this does, poached it from one of the google sites 
> I have been reviewing and tried to make it work?
>
> #This is the script I would like the output placed in PDF
> explanatory = c("claimStatusId", "AgeCat", "PatientGender", "PayorID")
> dependent = "AppealOverturned" # Appeals Status
> appdf1DT2 %>%
>   summary_factorlist(dependent, explanatory, p=TRUE, add_dependent_label=TRUE)
>
> #dev.off()
>
>
> str(appdf1DT2)
> # Classes 'data.table' and 'data.frame':   3983 obs. of  21 variables:
> #   $ ClaimServiceID   : Factor w/ 3983 levels "51318639","51318640",..: 1 2 
> 4 3 5 12 6 8 7 9 ...
> # $ LineNumber   : Factor w/ 140 levels "1","2","3","4",..: 1 2 4 3 5 7 1 
> 3 2 4 ...
> # $ claimStatusId: Factor w/ 2 levels "2","3": 2 2 2 2 2 1 1 1 1 1 ...
> # $ PatientGender: Factor w/ 3 levels "F","M","UNK": 2 2 2 2 2 1 1 1 1 1 
> ...
> # $ PayorID  : Factor w/ 19 levels "000","234","239",..: 1 1 1 1 1 1 
> 1 1 1 1 ...
> # $ AppealID : Factor w/ 512 levels "79765","116998",..: 1 1 1 1 1 2 
> 2 2 2 2 ...
> # $ ZipCode  : Factor w/ 223 levels "2155","3037",..: 72 72 72 72 72 
> 102 102 102 102 102 ...
> # $ EditID   : Factor w/ 21 levels "","0","001X",..: 2 12 8 12 8 8 2 
> 8 12 8 ...
> # $ CurrentBilled: num  14394 14394 14394 14394 14394 ...
> # $ ClaimLineSavings : num  0 0 0 0 0 ...
> # $ StatusChangeMo   : Factor w/ 7 levels "2018-01","2018-02",..: 4 4 4 4 4 4 
> 4 4 4 4 ...
> # $ Grouping : Factor w/ 9 levels "","Agencies",..: 4 4 4 4 4 4 4 4 4 
> 4 ...
> # $ AppealOverturned : Factor w/ 2 levels "1","2": 2 2 2 2 2 1 1 1 1 1 ...
> # $ PrimaryDX: Factor w/ 360 levels 

Re: [R] Help with knitr pkg

2018-07-19 Thread Rainer Hurling

Hi Bill,

Am 18.07.18 um 18:33 schrieb Bill Poling:

Hi,
I worked through this excellent tutorial:
#Elegant regression results tables and plots in R: the finalfit package
https://www.r-bloggers.com/elegant-regression-results-tables-and-plots-in-r-the-finalfit-package/



Now I am applying it to my own data.

In the tutorial there is mention of:

# Tables can be knitted to PDF, Word or html documents. We do this in
# RStudio from a .Rmd document. Example chunk:
#   ```{r, echo = FALSE, results='asis'}
# knitr::kable(example_table, row.names=FALSE,
#  align=c("l", "l", "r", "r", "r", "r"))
# ```

I am having a difficult time understanding how this works?

I have read through the help:

?knitr
#"This function takes an input file, extracts the R code in it according to a 
list of patterns, evaluates the code and writes the output in another file.
#It can also tangle R source code from the input document (purl() is a wrapper 
to knit(..., tangle = TRUE)).
#The knitr.purl.inline option can be used to also tangle the code of inline 
expressions (disabled by default)."

install.packages("knitr")
library(knitr)
?knit
?stitch
install.packages("stitch")#package 'stitch' is not available (for R version 
3.5.1)
?spin
install.packages("spin") #package 'spin' is not available (for R version 
3.5.1)Warning in install.packages :  Perhaps you meant 'SPIn' ?

I have also looked at the github and knitr author's links

https://github.com/yihui/knitr

https://yihui.name/knitr/demo/stitch/

https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.Rmd


If I understand this correctly I have to have a template already in place as 
the input object, is that correct? How would I construct this it that is so?

I also tried writing out directly to pdf and png with no success.

#pdf("c:/WHP/Appeals/OutputPDFs/EX V1.pdf")
#png("c:/WHP/Appeals/OutputPDFs/EX V1.png")
#opts_chunk$set(fig.path = "c:/WHP/Appeals/OutputPDFs/EX V1.pdf") <--I don't 
even understand what this does, poached it from one of the google sites I have been reviewing 
and tried to make it work?

#This is the script I would like the output placed in PDF
explanatory = c("claimStatusId", "AgeCat", "PatientGender", "PayorID")
dependent = "AppealOverturned" # Appeals Status
appdf1DT2 %>%
   summary_factorlist(dependent, explanatory, p=TRUE, add_dependent_label=TRUE)

#dev.off()


str(appdf1DT2)
# Classes 'data.table' and 'data.frame':   3983 obs. of  21 variables:
#   $ ClaimServiceID   : Factor w/ 3983 levels "51318639","51318640",..: 1 2 4 
3 5 12 6 8 7 9 ...
# $ LineNumber   : Factor w/ 140 levels "1","2","3","4",..: 1 2 4 3 5 7 1 3 
2 4 ...
# $ claimStatusId: Factor w/ 2 levels "2","3": 2 2 2 2 2 1 1 1 1 1 ...
# $ PatientGender: Factor w/ 3 levels "F","M","UNK": 2 2 2 2 2 1 1 1 1 1 ...
# $ PayorID  : Factor w/ 19 levels "000","234","239",..: 1 1 1 1 1 1 1 
1 1 1 ...
# $ AppealID : Factor w/ 512 levels "79765","116998",..: 1 1 1 1 1 2 2 
2 2 2 ...
# $ ZipCode  : Factor w/ 223 levels "2155","3037",..: 72 72 72 72 72 
102 102 102 102 102 ...
# $ EditID   : Factor w/ 21 levels "","0","001X",..: 2 12 8 12 8 8 2 8 
12 8 ...
# $ CurrentBilled: num  14394 14394 14394 14394 14394 ...
# $ ClaimLineSavings : num  0 0 0 0 0 ...
# $ StatusChangeMo   : Factor w/ 7 levels "2018-01","2018-02",..: 4 4 4 4 4 4 4 
4 4 4 ...
# $ Grouping : Factor w/ 9 levels "","Agencies",..: 4 4 4 4 4 4 4 4 4 4 
...
# $ AppealOverturned : Factor w/ 2 levels "1","2": 2 2 2 2 2 1 1 1 1 1 ...
# $ PrimaryDX: Factor w/ 360 levels "","8442","912",..: 2 2 2 2 2 171 
171 171 171 171 ...
# $ RevCodeCats  : Factor w/ 41 levels "AdminStorProcBlProd",..: 2 2 18 2 
18 18 2 2 2 18 ...
# $ AgeCat   : Factor w/ 9 levels "[0-5]","[11-20]",..: 4 4 4 4 4 8 8 8 
8 8 ...
# $ ClaimLevelSavings: num  0 0 0 0 0 ...
# - attr(*, ".internal.selfref")=

head(appdf1DT2)
ClaimServiceID LineNumber claimStatusId PatientGender PayorID ProviderID 
AppealID ZipCodeTIN EditID
1:   51318639  1 3 M 000 149385
79765  33904  0
2:   51318640  2 3 M 000 149385
79765  33904022
3:   51318642  4 3 M 000 149385
79765  33904   00504
4:   51318641  3 3 M 000 149385
79765  33904 022
5:   51318643  5 3 M 000 149385
79765  33904   00504
6:   85833537  7 2 F 0003240182   
116998  46635   00504
CurrentBilled ClaimLineSavings StatusChangeMo   
  Grouping AppealOverturned PrimaryDXRevCodeCats
1:  14394.0802018-04  Ambulatory Health Care 
Facilities2  8442AmbSurgCare
2:  14394.08