forked from linogaliana/python-datascientist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rprofile
279 lines (231 loc) · 13.1 KB
/
.Rprofile
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
if (file.exists("~/.Rprofile")) {
base::sys.source("~/.Rprofile", envir = environment())
}
options(blogdown.new_bundle = TRUE)
options(blogdown.hugo.version = "0.83.0")
options(blogdown.method = 'markdown')
options(blogdown.knit.on_save = FALSE)
reminder_jupyter <- function(file = "./content/getting-started/06_rappels_classes.Rmd",
out = "ipynb"){
sprintf(
"jupytext --to %s %s",
out,
file
)
}
download_badge <- function(notebook = "", github_link = 'https://github.com/linogaliana/python-datascientist'){
if (notebook == ""){
link <- sprintf(
"https://downgit.github.io/#/home?url=%s/blob/master/notebooks/course",
github_link
)
} else{
link <- sprintf(
"https://downgit.github.io/#/home?url=%s%s",
github_link,
notebook
)
}
return(
sprintf(
"[](%s)",
link
)
)
}
visualize_badge <- function(notebook = "", github_link = 'https://github.com/linogaliana/python-datascientist'){
if (notebook == ""){
nbviewer_link <- 'https://nbviewer.jupyter.org/github/linogaliana/python-datascientist/tree/master'
} else{
nbviewer_link <- sprintf(
'https://nbviewer.jupyter.org/github/linogaliana/python-datascientist/blob/master%s',
notebook
)
}
return(
sprintf(
"[](%s)",
nbviewer_link
)
)
}
reminder_badges <- function(notebook = "", onyxia_only = FALSE, split = NULL,
type = c("md", "html")){
type <- match.arg(type)
if (notebook != ""){
if (!endsWith(notebook, ".ipynb")){
notebook <- paste0(notebook, ".ipynb")
}
github_link <- 'https://github.com/linogaliana/python-datascientist/blob/master'
binder_path <- paste0("?filepath=",notebook)
notebook <- paste0('/', notebook)
nbviewer_link <- sprintf(
'https://nbviewer.jupyter.org/github/linogaliana/python-datascientist/blob/master%s',
notebook
)
chapter <- tools::file_path_sans_ext(basename(notebook))
section <- basename(dirname(notebook))
} else{
github_link <- 'https://github.com/linogaliana/python-datascientist'
binder_path <- ""
nbviewer_link <- 'https://nbviewer.jupyter.org/github/linogaliana/python-datascientist/tree/master'
}
if (type == "md"){
download_link <- sprintf(
"[](https://downgit.github.io/#/home?url=%s%s)",
github_link,
notebook
)
} else{
download_link <- sprintf(
'<a href="https://downgit.github.io/#/home?url=%s%s" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/Download-Notebook-important?logo=Jupyter" alt="Download"></a>',
github_link,
notebook
)
}
github_link <- sprintf('<a href="%s%s" class="github"><i class="fab fa-github"></i></a>',
github_link,
notebook)
if (type == "md"){
nbviewer_link <- paste0(
"[](",
nbviewer_link,")"
)
} else{
nbviewer_link <- sprintf(
'<a href="%s" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/Visualize-nbviewer-blue?logo=Jupyter" alt="nbviewer"></a>',
nbviewer_link
)
}
chapter <- tools::file_path_sans_ext(basename(notebook))
section <- basename(dirname(notebook))
onyxia_link_tmplt <- paste0(
"https://datalab.sspcloud.fr/launcher/inseefrlab-helm-charts-datascience/jupyter",
"?autoLaunch=true&onyxia.friendlyName=%C2%ABpython-datascience%C2%BB",
"&init.personalInit=%C2%ABhttps%3A%2F%2Fraw.githubusercontent.com%2Flinogaliana%2Fpython-datascientist%2Fmaster%2Fsspcloud%2Finit-jupyter.sh%C2%BB",
"&init.personalInitArgs=%C2%AB${section}%20${chapter}%C2%BB&security.allowlist.enabled=false"
)
onyxia_link_launcher <- stringr::str_interp(onyxia_link_tmplt, list(section=section, chapter=chapter))
if (type == "md"){
onyxia_link <- paste0(
"[]",
"(",onyxia_link_launcher,")"
)
} else{
onyxia_link <- sprintf(
'<a href="%s" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/SSPcloud-Tester%20via%20SSP--cloud-informational&color=yellow?logo=Python" alt="Onyxia"></a>',
onyxia_link_launcher
)
}
if (!is.null(split) && (4 %in% split)){
onyxia_link <- c(onyxia_link, "<br>")
}
if (type == "md"){
binder_link <- sprintf(
"[](https://mybinder.org/v2/gh/linogaliana/python-datascientist/master%s)",
binder_path
)
} else{
binder_link <- sprintf(
'<a href="https://mybinder.org/v2/gh/linogaliana/python-datascientist/master?filepath=%s" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/Launch-Binder-E66581.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olJXmsrmZYH1olL1olL0nFf1olJXmsrmZYH1olJXmsq8dZb1olJXmsrmZYH1olJXmspXmspXmsr1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olLeaIVXmsrmZYH1olL1olL1olJXmsrmZYH1olLna31Xmsr1olJXmsr1olJXmsrmZYH1olLqoVr1olJXmsr1olJXmsrmZYH1olL1olKkfaPobXvviGabgadXmsqThKuofKHmZ4Dobnr1olJXmsr1olJXmspXmsr1olJX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kaLiqQb+kGduJTNHG72zcW9LoJgqQxpP3/Tj//c3yB0tqzaml05/+orHLksVO+95kX7/7qgJvnjlrfr2Ggsyx0eoy9uPzN5SPd86aXggOsEKW2Prz7du3VID3/tzs/sSRs2w7ovVHKtjrX2pd7ZMlTxAYfBAL9jiDwfLkq55Tm7ifhMlTGPyCAs7RFRhn47JnlcB9RM5T97ASuZXIcVNuUDIndpDbdsfrqsOppeXl5Y+XVKdjFCTh+zGaVuj0d9zy05PPK3QzBamxdwtTCrzyg/2Rvf2EstUjordGwa/kx9mSJLr8mLLtCW8HHGJc2R5hS219IiF6PnTusOqcMl57gm0Z8kanKMAQg0qSyuZfn7zItsbGyO9QlnxY0eCuD1XL2ys/MsrQhltE7Ug0uFOzufJFE2PxBo/YAx8XPPdDwWN0MrDRYIZF0mSMKCNHgaIVFoBbNoLJ7tEQDKxGF0kcLQimojCZopv0OkNOyWCCg9XMVAi7ARJzQdM2QUh0gmBozjc3Skg6dSBRqDGYSUOu66Zg+I2fNZs/M3/f/Grl/XnyF1Gw3VKCez0PN5IUfFLqvgUN4C0qNqYs5YhPL+aVZYDE4IpUk57oSFnJm4FyCqqOE0jhY2SMyLFoo56zyo6becOS5UVDdj7Vih0zp+tcMhwRpBeLyqtIjlJKAIZSbI8SGSF3k0pA3mR5tHuwPFoa7N7reoq2bqCsAk1HqCu5uvI1n6JuRXI+S1Mco54YmYTwcn6Aeic+kssXi8XpXC4V3t7/ADuTNKaQJdScAAAAAElFTkSuQmCC" alt="Binder"></a>',
binder_path
)
}
if (!is.null(split) && (5 %in% split)){
binder_link <- c(binder_link, "<br>")
}
if (type == "md"){
colab_link <- sprintf("[](http://colab.research.google.com/github/linogaliana/python-datascientist/blob/master%s)",
notebook)
} else{
colab_link <- sprintf(
'<a href="http://colab.research.google.com/github/linogaliana/python-datascientist/blob/master%s" target="_blank" rel="noopener"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>',
notebook
)
}
if (!is.null(split) && (6 %in% split)){
colab_link <- c(colab_link, "<br>")
}
if (type == "md"){
vscode_link <- sprintf("[](https://github.dev/linogaliana/python-datascientist%s)",
notebook)
} else{
vscode_link <- sprintf(
'<a href="https://github.dev/linogaliana/python-datascientist%s" target="_blank" rel="noopener"><img src="https://open.vscode.dev/badges/open-in-vscode.svg" alt="githubdev"></a></p>',
notebook)
}
badges <- c(
github_link,
download_link,
nbviewer_link,
onyxia_link
)
if (isFALSE(onyxia_only)){
badges <- c(badges,
binder_link,
colab_link,
vscode_link)
}
if (type == "html") badges <- c('<p class="badges">', badges, '</p>')
return(
cat(badges, sep = "\n")
)
}
print_badges <- function(fpath = NULL, onyxia_only = FALSE, split = 4){
if (is.null(fpath)){
fpath <- knitr::current_input(dir = TRUE)
}
fpath <- gsub(paste0(here::here(),"/./"), "", fpath)
fpath <- gsub("Rmd", "ipynb", fpath)
fpath <- gsub("content","notebooks",fpath)
reminder_badges(fpath, onyxia_only = onyxia_only, split = split)
}
github_link <- function(fpath = NULL){
if (is.null(fpath)){
fpath <- knitr::current_input(dir = TRUE)
}
fpath <- gsub(paste0(here::here(),"/./"), "", fpath)
fpath <- gsub("Rmd", "ipynb", fpath)
fpath <- gsub("content","notebooks",fpath)
return(fpath)
}
reminder_box <- function(boxtype = "warning", type = c("html","markdown")){
type <- match.arg(type)
icon <- switch(boxtype,
warning = "fa fa-exclamation-triangle",
hint = "fa fa-lightbulb",
tip = "fa fa-lightbulb",
note = "fa fa-comment",
exercise = "fas fa-pencil-alt")
box <- c(
sprintf(
'{{< panel status="%s" title="%s" icon="%s" >}}',
boxtype,
Hmisc::capitalize(boxtype),
icon
),
"Example",
"{{< /panel >}}"
)
if (type == "html") cat(box, sep = "\n")
box <- gsub("<","%", box)
box <- gsub(">","%", box)
cat(box, sep = "\n")
}
# Hook from Maelle Salmon: https://ropensci.org/technotes/2020/04/23/rmd-learnings/
modif_plot <- function(x, options, dir_path) {
hugoopts <- options$hugoopts
paste0(
"{", "{<figure src=", # the original code is simpler
# but here I need to escape the shortcode!
'"', paste0(dir_path,"/",x), '" ',
if (!is.null(hugoopts)) {
glue::glue_collapse(
glue::glue('{names(hugoopts)}="{hugoopts}"'),
sep = " "
)
},
">}}\n"
)
}
message("For local preview when the pages are built: blogdown::hugo_build(local = TRUE)")