-
Notifications
You must be signed in to change notification settings - Fork 8
/
RubyText.Rmd
executable file
·376 lines (309 loc) · 12.7 KB
/
RubyText.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
---
title: "<span style='color:goldenrod'>RMarkdown导入/引用外来编程语</span>"
subtitle: '外来编程语'
author: "[雷欧 ∪ 瑞欧,黄联富](https://englianhu.github.io) <img src='文诸子百家考工记/ENG.png'
height='16' align='center' valign='middle'> <img src='诸子百家考工记/赢家ξng黄氏江夏堂 - 量化对冲(中).png'
height='16' align='center' valign='middle'>®"
tags: [计量经济学, 量化圈, 娱乐圈, ®, Python, ®Studio]
date: "13-Apr-2022"
output:
html_document:
mathjax: https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
number_sections: yes
highlight: haddock
toc: yes
toc_depth: 6
toc_float:
collapsed: yes
smooth_scroll: yes
code_folding: hide
css: CSSBackgrounds.css
fig_caption: yes
---
runtime: shiny
![](诸子百家考工记/江夏堂(甲).png)
# 设定
## SCSS 设置
<style>
pre {
overflow-x: auto;
}
pre code {
word-wrap: normal;
white-space: pre;
}
.table-hover > tbody > tr:hover {
background-color: #8D918D;
}
</style>
```{r load-sass, class.source='bg-success', class.output='bg-primary'}
# install.packages('remotes', dependencies = TRUE, INSTALL_opts = '--no-lock')
library('BBmisc', 'rmsfuns')
#remotes::install_github("rstudio/sass")
lib('sass')
## https://support.rstudio.com/hc/en-us/articles/200532197
## https://community.rstudio.com/t/r-does-not-display-korean-chinese/30889/3?u=englianhu
#Sys.setlocale("LC_CTYPE", "en_US.UTF-8")
#Sys.setlocale("LC_CTYPE", "zh_CN.UTF-8")
#Sys.setlocale(category = "LC_CTYPE", "Chinese (Simplified)_China.936")
#Sys.setlocale(locale = "Chinese")
#Sys.setlocale(locale = "Japanese")
#Sys.setlocale(locale = "English")
# rmarkdown::render('/home/englianhu/Documents/owner/ryo-cn.Rmd', encoding = 'UTF-8')
#Sys.setlocale("LC_CTYPE", "UTF-8")
#Sys.setlocale(locale = "UTF-8")
#Sys.setlocale(category = "LC_ALL", locale = "chs")
#Sys.setlocale(category = "LC_ALL", locale = "UTF-8")
#Sys.setlocale(category = "LC_ALL", locale = "Chinese")
#Sys.setlocale(category = "LC_ALL", locale = "zh_CN.UTF-8")
Sys.setlocale("LC_ALL", "en_US.UTF-8")
```
```{scss set-scss, class.source='bg-success', class.output='bg-primary'}
/* https://stackoverflow.com/a/66029010/3806250 */
h1 { color: #002C54; }
h2 { color: #2F496E; }
h3 { color: #375E97; }
h4 { color: #556DAC; }
h5 { color: #92AAC7; }
/* ----------------------------------------------------------------- */
/* https://gist.github.com/himynameisdave/c7a7ed14500d29e58149#file-broken-gradient-animation-less */
.hover01 {
/* color: #FFD64D; */
background: linear-gradient(155deg, #EDAE01 0%, #FFEB94 100%);
transition: all 0.45s;
&:hover{
background: linear-gradient(155deg, #EDAE01 20%, #FFEB94 80%);
}
}
.hover02 {
color: #FFD64D;
background: linear-gradient(155deg, #002C54 0%, #4CB5F5 100%);
transition: all 0.45s;
&:hover{
background: linear-gradient(155deg, #002C54 20%, #4CB5F5 80%);
}
}
.hover03 {
color: #FFD64D;
background: linear-gradient(155deg, #A10115 0%, #FF3C5C 100%);
transition: all 0.45s;
&:hover{
background: linear-gradient(155deg, #A10115 20%, #FF3C5C 80%);
}
}
```
```{r gb-opts, class.source='hover01', class.output='hover02'}
## Set the timezone but not change the datetime
Sys.setenv(TZ = 'Asia/Shanghai')
## Setting to omit all warnings
## https://stackoverflow.com/a/36846793/3806250
## Set width
## options(knitr.table.format = 'html') will set all kableExtra tables to be 'html', otherwise need to set the parameter on every single table.
options(warn = -1, width = 999, knitr.table.format = 'html')#, digits.secs = 6)
## https://stackoverflow.com/questions/39417003/long-vectors-not-supported-yet-abnor-in-rmd-but-not-in-r-script
## https://yihui.org/knitr/options
knitr::opts_chunk$set(
class.source = 'hover01', class.output = 'hover02', class.error = 'hover03',
message = FALSE, warning = FALSE, error = TRUE,
autodep = TRUE, aniopts = 'loop',
progress = TRUE, verbose = TRUE,
cache = FALSE, cache.lazy = FALSE, result = 'asis')
```
<br><br>
## 设置
```{r libs, eval=FALSE}
## Setup Options, Loading Required Libraries and Preparing Environment
## Loading the packages and setting adjustment
source('函数/读取程序包配套.R')
```
```{r setup, include=FALSE}
## Setup Options, Loading Required Libraries and Preparing Environment
## Loading the package 'BBmisc'
if (suppressMessages(!require('BBmisc'))) {
install.packages('BBmisc', dependencies = TRUE, INSTALL_opts = '--no-lock')
suppressMessages(library('BBmisc'))
}
if (suppressMessages(!require('rmsfuns'))) {
install.packages('rmsfuns', dependencies = TRUE, INSTALL_opts = '--no-lock')
suppressMessages(library('rmsfuns'))
}
if (!require('REmap')) devtools::install_github('lchiffon/REmap')
## Loading multiple packages at once
pkgs <- c('readr', 'plyr', 'dplyr', 'magrittr', 'tidyverse', 'devtools', 'remotes', 'zoo', 'lubridate', 'stringr', 'rvest', 'markdown', 'googleVis', 'knitr', 'rmarkdown', 'htmltools', 'knitr', 'kableExtra', 'formattable', 'echarts4r', 'radarchart', 'MASS', 'htmlwidgets', 'maps', 'REmap', 'ggmap', 'vembedr')
suppressAll(lib(pkgs))
load_pkg(pkgs)
rm(pkgs)
## Set the googleVis options first to change the behaviour of plot.gvis, so that
## only the chart component of the HTML file is written into the output file.
op <- options(gvis.plot.tag = 'chart')
## <audio src='文艺坊曲库/bigmoney.mp3' autoplay controls loop></audio>
```
<br><br>
# 外来编程语
## Ruby 鲁比
```{r setup-ruby}
require('BBmisc')
## 网上有好几个 runr R语言程序包,需要安装 yihui 的程序包
## https://github.com/chiefbiiko/runr
## https://github.com/christian-million/runr
## https://github.com/yihui/runr 🇨🇳
if (!require('runr')) devtools::install_github('yihui/runr')
pkgs <- c('knitr', 'runr')
lib(pkgs)
names(knitr::knit_engines$get())
#rb = proc_ruby()
#rb$start()
#knit_engines$set(ruby = function(options) {
# knitr:::sew(rb$exec(options$code), options)
#})
opts_chunk$set(
engine = 'ruby', warning = FALSE, message = FALSE, error = TRUE, result = 'asis'
# engine.path = list(
# python = '~/anaconda/bin/python',
# ruby = '/usr/local/bin/ruby')
)
## Set the timezone but not change the datetime
Sys.setenv(TZ = 'Asia/Shanghai')
## Setting to omit all warnings
## https://stackoverflow.com/a/36846793/3806250
## Set width
## options(knitr.table.format = 'html') will set all kableExtra tables to be 'html', otherwise need to set the parameter on every single table.
options(warn = -1, width = 999, knitr.table.format = 'html')#, digits.secs = 6)
```
```{ruby}
hello = 'Hello!'
print hello
```
```{ruby heading}
## https://towardsdatascience.com/how-to-do-reproducible-research-in-ruby-with-gknit-c26d2684d64e
outputs "### #{@c}"
```
```{ruby error=TRUE}
# Install API
gem install google-finance-ruby-client
# Pull Microsoft stock price
prices = GoogleFinance::History.get('MSFT', start_date: Date.parse('2016-01-03'), end_date: Date.parse('2016-01-10'))
print prices
```
```{ruby error=TRUE}
def mean(arr)
arr.inject(:+).to_f / arr.length
end
print mean((1..5).to_a)
```
```{ruby error=TRUE}
#rb$stop()
```
```{r error=TRUE}
x=system('ruby -e "puts 1+1"', intern=TRUE)
x
x=system('perl -e "print 2 + 4"', intern=TRUE)
x
```
```{bash error=TRUE}
ruby -e "puts '<ruby>건설<rt>geonseol</rt>중<rt>jung</rt></ruby>'"
```
<ruby>건설<rt>geonseol</rt>중<rt>jung</rt></ruby>
```{r error=TRUE}
HTML('<ruby>건설<rp>(</rp><rt>geonseol</rt><rp>)</rp>중<rp>(</rp><rt>jung</rt><rp>)</rp></ruby> !')
```
```{r error=TRUE}
shiny::runGitHub('multilingualShinyApp', 'chrislad')
```
```{r error=TRUE}
runUrl('https://github.com/chrislad/multilingualShinyApp')
```
## C\#
```{r error=TRUE}
# install.packages("remotes")
if (!require('dotnet')) remotes::install_github('bearloga/dotnet')
lib('dotnet')
dotnet::register_engine()
```
```{dotnet error=TRUE}
using System;
```
```{dotnet error=TRUE}
using System;
class Program {
static void Main(string[] args) {
Console.WriteLine("Hello from R Markdown!");
}
}
```
```{dotnet error=TRUE}
cs_engine = function(options) {
done_signal = uuid::UUIDgenerate()
#print(paste("done", done_signal))
if (length(options$code) == 1) {
process_write(handle, paste0(options$code, '\nConsole.WriteLine("', done_signal, '");\n'))
} else {
process_write(handle, paste0(paste(options$code, collapse = "\n"), '\nConsole.WriteLine("', done_signal, '");\n'))
}
out = ""
while(TRUE) {
on_the_way_in = process_read(handle, timeout = 1000)$stdout
out = paste0(out, on_the_way_in)
if (any(grepl(done_signal, out))) {
#print("FOUND IT!")
#print(out)
break
}
#print("No Done Signal Yet.")
#print(out)
}
knitr::engine_output(options, options$code, str_replace_all(out, done_signal, ""))
}
knitr::knit_engines$set(cs = cs_engine)
```
```{dotnet error=TRUE}
Console.WriteLine("Hello World!");
```
‵
```{dotnet error=TRUE}
public static async Task<string> PostWebAsync(string url, string idata) {
var request = (HttpWebRequest)WebRequest.Create(url);
var data = Encoding.ASCII.GetBytes(idata);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = await request.GetRequestStreamAsync()) {
await stream.WriteAsync(data, 0, data.Length);
}
var response = (HttpWebResponse)await request.GetResponseAsync();
var r = new StreamReader(response.GetResponseStream());
// System.Windows.MessageBox.Show(await r.ReadToEndAsync());
return await r.ReadToEndAsync();
}
// string data = PostWebAsync("http://fanyi.baidu.com/v2transapi","from=auto&to={Translated Language}&query={Contents of Translation}&transtype=realtime&simple_means_flag=3");
```
<br><br>
# 参考文献
- [GitHub@yihui/runr](https://github.com/yihui/runr) 🔥
- [GitHub@ash1day/rbplotly](https://github.com/ash1day/rbplotly)
- [GitHub@matt-dray/badgr-shiny.R](https://gist.github.com/matt-dray/cda4a3facb6b1ca848a8ddbcc885a669) 🔥
- [](https://community.rstudio.com/t/how-to-start-a-new-project-using-a-badge-in-githubs-readme-md/87370) 🔥
- [Run Ruby from R](https://rpubs.com/y4ashida/ruby-knitr) 🔥
- [Add 'Calculation In Process' Indicator for Shiny Application](https://www.r-bloggers.com/2014/01/add-calculation-in-process-indicator-for-shiny-application) 🔥
- [Shiny ruby polygonal font. Crystal style A and B letters](https://www.123rf.com/photo_28905643_shiny-ruby-polygonal-font-crystal-style-a-and-b-letters.html) 🔥
- [Calling Ruby, Perl or Python from R](https://www.r-bloggers.com/2010/06/calling-ruby-perl-or-python-from-r)
- [2.7 Other language engines](https://bookdown.org/yihui/rmarkdown/language-engines.html) 🔥
- [Chunk options and package options](https://yihui.org/knitr/options) 🔥
- [比adminlte数据可视化页面更好的选择](https://www.fanruan.com/bw/absj) 🔥
- [Ruby on Rails For Dummies](https://books.google.com.my/books?id=CHx7Cb9a32cC&pg=PT86&lpg=PT86&dq=apply+ruby+text+on+r+shiny&source=bl&ots=U7jZJn67ka&sig=ACfU3U3s_ZN6GwjKjwdmg2V-5oq5buVtWg&hl=zh-CN&sa=X&ved=2ahUKEwi-842v4I73AhX_3zgGHcthDHgQ6AF6BAghEAM#v=onepage&q=apply%20ruby%20text%20on%20r%20shiny&f=false)
- [Benchmark Ruby Code with R, rsruby and better-benchmark](https://smartlogic.io/blog/2008-10-08-benchmark-ruby-code-with-r-rsruby-and-better-benchmark)
- [How to do reproducible research in Ruby with gKnit](https://towardsdatascience.com/how-to-do-reproducible-research-in-ruby-with-gknit-c26d2684d64e)
- [How to run Ruby code from terminal?](https://stackoverflow.com/questions/12378818/how-to-run-ruby-code-from-terminal)
- [How to execute a Ruby script in Terminal?](https://stackoverflow.com/questions/8721369/how-to-execute-a-ruby-script-in-terminal)
- [Run shell script in shiny](https://stackoverflow.com/questions/48298462/run-shell-script-in-shiny)
- [Can you run a Ruby script in a Rmarkdown file](https://community.rstudio.com/t/can-you-run-a-ruby-script-in-a-rmarkdown-file/93165)
- [How to install and load Ruby packages in R](https://community.rstudio.com/t/how-to-install-and-load-ruby-packages-in-r/93287)
- [rubydown](https://github.com/genya0407/rbmark)
- [RMarkdown : Code Languages](https://rmarkdown.rstudio.com/lesson-5.html)
- [Introducing `dotnet` knitr engine for C# & F# chunks in R Markdown](https://mpopov.com/blog/2020/06/10/introducing-dotnet-knitr-engine)
- [rmarcksharpdown](https://jasonpunyon.com/blog/2019/01/04/rmarcksharpdown)
- [Programmer Group : Baidu Translation of Daily API](https://programmer.group/baidu-translation-of-daily-api.html)
<br><br>
---
[<img src='诸子百家考工记/世博量化.png' height='16'/> Sςιβrοκεrs Trαdιηg®](http://www.scibrokes.com)<br>
<span style='color:RoyalBlue'>**[<img src='诸子百家考工记/世博量化.png' height='16'/> 世博量化®](http://www.scibrokes.com)企业知识产权®及版权®所有,盗版必究。**</span>