Skip to content

Commit 45bcc35

Browse files
committed
Bloomr: +.br.inittex
1 parent 7b3c9d0 commit 45bcc35

File tree

6 files changed

+96
-70
lines changed

6 files changed

+96
-70
lines changed

latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _Change details_
2525
bloomr.sys.R: +q/quit, -.br.testBR, -br.getLatexAddons, -br.getPandoc, -.br.getPandoc.release, -download.bin,
2626
-dbr.brmain, +.br.home
2727
bloomr.rmd: +.br.addpaths, +perl, ~br.rmd2both, ~br.rmd2pdf, ~br.rmd2html, ~br.md2pdf, +buildenv, +br.rmd2slides,
28-
+.br.pathexe
28+
+.br.pathexe, .br.inittex()
2929
'bloomr' env follows package 'stats' position and not 'base', the assign is compatible with recent R.
3030
bloomr.beta.Rmd: 'bloomr' env follows package 'stats' as for bloomr.rmd.
3131
xlx.R: plyr:::rbind.fill without loading package to avoid conflicts.

src/bloomr.R

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## ----store, opts.label='purlme'----------------------------------------------------------------------------------------------------
1+
## ----store, opts.label='purlme'-----------------------------------------------
22
## Purl this first
33
## Store br.* objects in bloomr env in base namespace
44
assign('bloomr.usr', new.env(parent=asNamespace("stats")))
@@ -18,7 +18,7 @@ store=function(sym){
1818
}
1919

2020

21-
## ----br.bdh, opts.label='purlme'---------------------------------------------------------------------------------------------------
21+
## ----br.bdh, opts.label='purlme'----------------------------------------------
2222
br.bdh=function(
2323
con, securities, fields="PX_LAST", start.date, end.date = NULL,
2424
option.names = NULL, option.values = NULL,
@@ -32,7 +32,7 @@ br.bdh=function(
3232
}
3333
store(br.bdh)
3434

35-
## ----br.bulk.csv, opts.label='purlme'----------------------------------------------------------------------------------------------
35+
## ----br.bulk.csv, opts.label='purlme'-----------------------------------------
3636
br.bulk.csv=function(con, file, start=Sys.Date()-5, field="PX_LAST", cols=NULL,
3737
addtype=FALSE, showtype=FALSE, use.xts=TRUE, comma=TRUE,
3838
price=TRUE, nrow=5, same.dates=FALSE, no.na=FALSE, empty.sec=0
@@ -77,7 +77,7 @@ br.bulk.csv=function(con, file, start=Sys.Date()-5, field="PX_LAST", cols=NULL,
7777
}
7878
store(br.bulk.csv)
7979

80-
## ----br.bulk.desc, opts.label='purlme'---------------------------------------------------------------------------------------------
80+
## ----br.bulk.desc, opts.label='purlme'----------------------------------------
8181
br.bulk.desc=function(con, tiks) {
8282

8383
LL = lapply(tiks, function(tik){
@@ -89,7 +89,7 @@ br.bulk.desc=function(con, tiks) {
8989
}
9090
store(br.bulk.desc)
9191

92-
## ----br.bulk.idx, opts.label='purlme'----------------------------------------------------------------------------------------------
92+
## ----br.bulk.idx, opts.label='purlme'-----------------------------------------
9393
br.bulk.idx=function(con, index, start=Sys.Date()-5, field="PX_LAST", showtype=FALSE,
9494
include.idx=TRUE, use.xts=TRUE,
9595
nsec=10, price=TRUE, nrow=5,
@@ -139,7 +139,7 @@ br.bulk.idx=function(con, index, start=Sys.Date()-5, field="PX_LAST", showtype=F
139139
}
140140
store(br.bulk.idx)
141141

142-
## ----br.bulk.tiks, opts.label='purlme'---------------------------------------------------------------------------------------------
142+
## ----br.bulk.tiks, opts.label='purlme'----------------------------------------
143143
br.bulk.tiks=function(
144144
con,
145145
tiks,
@@ -223,7 +223,7 @@ br.bulk.tiks=function(
223223
}
224224
store(br.bulk.tiks)
225225

226-
## ----br.desc, opts.label='purlme'--------------------------------------------------------------------------------------------------
226+
## ----br.desc, opts.label='purlme'---------------------------------------------
227227
br.desc=function(con, tik)
228228
{
229229

@@ -252,7 +252,7 @@ br.desc=function(con, tik)
252252
}
253253
store(br.desc)
254254

255-
## ----rmd-internal, opts.label='purlme'---------------------------------------------------------------------------------------------
255+
## ----rmd-internal, opts.label='purlme'----------------------------------------
256256
.br.addpaths <- function(pandonly = FALSE, quiet = TRUE){
257257
### Add to Windows System Path the executable directories of LaTeX, Pandoc, and Perl with this search priority, and
258258
### return invisibly the original path. If "pandonly" is true, add only Pandoc. If "quiet" is false, print the new path.
@@ -270,9 +270,12 @@ store(br.desc)
270270
}
271271

272272
pandir <- xfind("pandoc/bin/pandoc.exe")
273-
latdir <- xfind("tinytex/bin/win32/latex.exe")
274-
perldir <- xfind("tinytex/tlpkg/tlperl/bin/perl.exe")
275-
273+
if(!pandonly){
274+
latdir <- xfind("tinytex/bin/win32/latex.exe")
275+
perldir <- xfind("tinytex/tlpkg/tlperl/bin/perl.exe")
276+
.br.inittex()
277+
}
278+
276279
## Add executable dirs to system path
277280
old.path <- Sys.getenv('Path')
278281
ap <- function(dir) Sys.setenv(PATH=paste0(dir, ";", Sys.getenv("PATH")))
@@ -317,17 +320,22 @@ store(br.desc)
317320
})
318321
}
319322

323+
.br.inittex <- function(){
324+
library('tinytex')
325+
options(tinytex.tlmgr.path = file.path(.br.home(), "tinytex/bin/win32/tlmgr.bat"))
326+
}
320327

321328

322-
## ----br.md2pdf, opts.label='purlme'------------------------------------------------------------------------------------------------
329+
330+
## ----br.md2pdf, opts.label='purlme'-------------------------------------------
323331
br.md2pdf <- function(md.file, pdf.file, quiet=TRUE){
324332
### Make a markdown file into a PDF
325333
### You need the proper BloomR version
326334

327335
## Test arguments
328336
if(missing(md.file)) stop("Argument 'md.file' missing.")
329337
if(missing(pdf.file)) pdf.file=paste0(tools:::file_path_sans_ext(md.file), '.pdf')
330-
338+
331339
## Set executable paths and render
332340
cmd <- paste("pandoc", .br.wpath(md.file), '-o', .br.wpath(pdf.file))
333341
cmdexpr <- quote(system(cmd, intern = TRUE, invisible = FALSE))
@@ -336,7 +344,7 @@ br.md2pdf <- function(md.file, pdf.file, quiet=TRUE){
336344
}
337345
store(br.md2pdf)
338346

339-
## ----br.rmd2html, opts.label='purlme'----------------------------------------------------------------------------------------------
347+
## ----br.rmd2html, opts.label='purlme'-----------------------------------------
340348
br.rmd2html <- function(rmd.file, html.file, quiet=TRUE){
341349
### Make an R Markdown file into a HTML self-contained file
342350
### You need the proper BloomR edition
@@ -362,7 +370,7 @@ br.rmd2html <- function(rmd.file, html.file, quiet=TRUE){
362370
}
363371
store(br.rmd2html)
364372

365-
## ----br.rmd2slides, opts.label='purlme'--------------------------------------------------------------------------------------------
373+
## ----br.rmd2slides, opts.label='purlme'---------------------------------------
366374
br.rmd2slides <- function(rmd.file, html.file, quiet=TRUE){
367375
### Make an R Markdown file into a Google Slides self-contained HTML file
368376
### You need proper BloomR edition
@@ -391,7 +399,7 @@ br.rmd2slides <- function(rmd.file, html.file, quiet=TRUE){
391399
store(br.rmd2slides)
392400

393401

394-
## ----br.rmd2pdf, opts.label='purlme'-----------------------------------------------------------------------------------------------
402+
## ----br.rmd2pdf, opts.label='purlme'------------------------------------------
395403
br.rmd2pdf=function(rmd.file, pdf.file, quiet=TRUE){
396404
### Make an R Markdown file into a PDF
397405
### You need BloomR LaTeX addons or the proper BloomR version
@@ -418,7 +426,7 @@ br.rmd2pdf=function(rmd.file, pdf.file, quiet=TRUE){
418426
}
419427
store(br.rmd2pdf)
420428

421-
## ----br.rmd2both, opts.label='purlme'----------------------------------------------------------------------------------------------
429+
## ----br.rmd2both, opts.label='purlme'-----------------------------------------
422430
br.rmd2both=function(rmd.file, quiet=TRUE){
423431
### Make an R Markdown file into a PDF and an HTML self-contained file
424432
### You need BloomR LaTeX addons or the proper BloomR version
@@ -467,7 +475,7 @@ br.rmd2both=function(rmd.file, quiet=TRUE){
467475
store(br.rmd2both)
468476

469477

470-
## ----br.sample, opts.label='purlme'------------------------------------------------------------------------------------------------
478+
## ----br.sample, opts.label='purlme'-------------------------------------------
471479
br.sample=function(nrow, nsec=1, price=TRUE, start=Sys.Date(), mean=ifelse(price, 10, 0.1), sd=1,
472480
jitter=0, same.dates=FALSE, no.na=FALSE, df=FALSE, empty.sec=0, sec.names=NULL)
473481
{
@@ -534,13 +542,13 @@ br.sample=function(nrow, nsec=1, price=TRUE, start=Sys.Date(), mean=ifelse(price
534542
}
535543
store(br.sample)
536544

537-
## ----deprecated, opts.label='purlme'-----------------------------------------------------------------------------------------------
545+
## ----deprecated, opts.label='purlme'------------------------------------------
538546
bbg.open=function() stop("Sorry 'bbg.open' is now deprecated. Please use br.open().")
539547
bbg.close=function(con) stop("Sorry 'bbg.close' is now deprecated. Please use br.close().")
540548
store(bbg.open)
541549
store(bbg.close)
542550

543-
## ----bbg-internal, opts.label='purlme'---------------------------------------------------------------------------------------------
551+
## ----bbg-internal, opts.label='purlme'----------------------------------------
544552

545553
## Check connection token
546554
.br.is.con=function(con) identical(attr(con, 'jclass'), "org/findata/blpwrapper/Connection")
@@ -577,14 +585,14 @@ store(.br.check.type)
577585
store(.br.cuttype)
578586
store(.br.jar)
579587

580-
## ----connections, opts.label='purlme'----------------------------------------------------------------------------------------------
588+
## ----connections, opts.label='purlme'-----------------------------------------
581589
br.open=function() blpConnect(blpapi.jar.file=.br.jar())
582590
br.close=function(conn) if(!is.null(conn)) blpDisconnect(conn)
583591

584592
store(br.open)
585593
store(br.close)
586594

587-
## ----miscfunc, opts.label='purlme'-------------------------------------------------------------------------------------------------
595+
## ----miscfunc, opts.label='purlme'--------------------------------------------
588596

589597
#Clean up
590598
## Remove visible and invisible objects
@@ -598,7 +606,7 @@ rm.var=function()
598606
store(rm.all)
599607
store(rm.var)
600608

601-
## ----betafun, opts.label='purlme'--------------------------------------------------------------------------------------------------
609+
## ----betafun, opts.label='purlme'---------------------------------------------
602610

603611
br.beta=function(){
604612
f=paste0(R.home("share"), "/bloomr/bloomr.beta.R")
@@ -608,7 +616,7 @@ br.beta=function(){
608616
store(br.beta)
609617

610618

611-
## ----time, opts.label='purlme'-----------------------------------------------------------------------------------------------------
619+
## ----time, opts.label='purlme'------------------------------------------------
612620
`%+%` <- function(x,y) UseMethod("%+%")
613621
`%+%.Date` <- function(date,n) seq(date, by = paste (n, "months"), length = 2)[2]
614622
`%-%` <- function(x,y) UseMethod("%-%")
@@ -664,7 +672,7 @@ store(last.day)
664672
store(day.us)
665673

666674

667-
## ----attach, opts.label='purlme'---------------------------------------------------------------------------------------------------
675+
## ----attach, opts.label='purlme'----------------------------------------------
668676
### Make visible br.* in bloomr env and base ns
669677
attach(bloomr.usr)
670678
rm(store)

src/bloomr.Rmd

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,12 @@ store(br.desc)
805805
}
806806
807807
pandir <- xfind("pandoc/bin/pandoc.exe")
808-
latdir <- xfind("tinytex/bin/win32/latex.exe")
809-
perldir <- xfind("tinytex/tlpkg/tlperl/bin/perl.exe")
810-
808+
if(!pandonly){
809+
latdir <- xfind("tinytex/bin/win32/latex.exe")
810+
perldir <- xfind("tinytex/tlpkg/tlperl/bin/perl.exe")
811+
.br.inittex()
812+
}
813+
811814
## Add executable dirs to system path
812815
old.path <- Sys.getenv('Path')
813816
ap <- function(dir) Sys.setenv(PATH=paste0(dir, ";", Sys.getenv("PATH")))
@@ -852,6 +855,11 @@ store(br.desc)
852855
})
853856
}
854857
858+
.br.inittex <- function(){
859+
library('tinytex')
860+
options(tinytex.tlmgr.path = file.path(.br.home(), "tinytex/bin/win32/tlmgr.bat"))
861+
}
862+
855863
856864
```
857865

@@ -898,7 +906,7 @@ br.md2pdf <- function(md.file, pdf.file, quiet=TRUE){
898906
## Test arguments
899907
if(missing(md.file)) stop("Argument 'md.file' missing.")
900908
if(missing(pdf.file)) pdf.file=paste0(tools:::file_path_sans_ext(md.file), '.pdf')
901-
909+
902910
## Set executable paths and render
903911
cmd <- paste("pandoc", .br.wpath(md.file), '-o', .br.wpath(pdf.file))
904912
cmdexpr <- quote(system(cmd, intern = TRUE, invisible = FALSE))

src/bloomr.html

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ <h2>Demonstration</h2>
390390
<pre class="r"><code>con=NULL #Simulated mode: replace with con=br.open() on terminal</code></pre>
391391
<pre class="r"><code>data=br.bulk.csv(con, &quot;mybloomr/tickers.csv&quot;) </code></pre>
392392
<pre><code>## Processing Financial ...</code></pre>
393+
<pre><code>##
394+
## Attaching package: &#39;zoo&#39;</code></pre>
395+
<pre><code>## The following objects are masked from &#39;package:base&#39;:
396+
##
397+
## as.Date, as.Date.numeric</code></pre>
393398
<pre><code>## Loading 3988 HK Equity</code></pre>
394399
<pre><code>## Loading C US Equity</code></pre>
395400
<pre><code>## Loading 601288 CH Equity</code></pre>
@@ -410,26 +415,25 @@ <h2>Demonstration</h2>
410415
<pre class="r"><code>data</code></pre>
411416
<pre><code>## $Financial
412417
## 3988 HK C US 601288 CH BAC US HSBA LN
413-
## 2022-03-16 10.52 NA 10.309 9.270 9.730
414-
## 2022-03-17 NA 8.875 9.361 NA 9.934
415-
## 2022-03-18 NA NA 10.865 11.844 10.624
416-
## 2022-03-19 NA 8.580 10.662 9.594 NA
418+
## 2022-03-15 NA 8.210 10.089 12.012 NA
419+
## 2022-03-16 NA 9.891 11.129 NA NA
420+
## 2022-03-17 9.67 NA 8.560 10.903 NA
421+
## 2022-03-18 NA 9.888 NA 10.710 8.956
422+
## 2022-03-19 NA NA 10.171 9.052 9.371
417423
##
418424
## $Technology
419425
## QCOM US CSCO US 700 HK IBM US INTC US
420-
## 2022-03-15 9.255 NA NA 10.693 10.074
421-
## 2022-03-16 9.779 NA 10.310 NA 10.803
422-
## 2022-03-17 8.919 9.457 9.731 9.849 NA
423-
## 2022-03-18 NA 9.615 NA 10.387 NA
424-
## 2022-03-19 10.010 10.890 10.045 NA NA
426+
## 2022-03-16 10.113 NA 10.688 10.871 12.725
427+
## 2022-03-17 NA 10.402 NA 10.769 NA
428+
## 2022-03-18 NA 9.939 NA 10.457 NA
429+
## 2022-03-19 NA 9.748 NA NA NA
425430
##
426431
## $Indices
427-
## DJI DJUSFN W1TEC
428-
## 2022-03-15 9.738 11.342 NA
429-
## 2022-03-16 NA 11.145 9.763
430-
## 2022-03-17 11.166 9.727 NA
431-
## 2022-03-18 10.836 9.998 8.085
432-
## 2022-03-19 NA 9.236 7.908</code></pre>
432+
## DJI DJUSFN W1TEC
433+
## 2022-03-15 NA 10.505 9.096
434+
## 2022-03-17 NA NA 8.873
435+
## 2022-03-18 10.002 NA 9.050
436+
## 2022-03-19 9.310 NA 11.294</code></pre>
433437
<p>Note:</p>
434438
<ul>
435439
<li><p>The name of the securities tickers is stored without the security type: “Equity”, “Index”, etc.<br />
@@ -606,11 +610,9 @@ <h2>Example</h2>
606610
<pre><code>## Loading MSFT US Equity</code></pre>
607611
<pre><code>## Loading AMZN US Equity</code></pre>
608612
<pre><code>## MSFT US AMZN US
609-
## 2022-03-15 10.137 NA
610-
## 2022-03-16 9.036 NA
611-
## 2022-03-17 NA 11.410
612-
## 2022-03-18 10.900 NA
613-
## 2022-03-19 11.194 9.715</code></pre>
613+
## 2022-03-17 10.975 NA
614+
## 2022-03-18 8.950 NA
615+
## 2022-03-19 NA 9.5</code></pre>
614616
<pre class="r"><code>br.close(con) # Use the token to release the connection</code></pre>
615617
</div>
616618
<div id="see-also" class="section level2">

0 commit comments

Comments
 (0)