Khám phá RStudio (Advanced) : Add-in và tùy biến phím tắt dùng trong Addin

Trong post này, tôi sẽ trình bày các kinh nghiệm của mình trong sử dụng R Studio liên quan tới dùng các gói lệnh Add-in và vận dụng trong nghiên cứu và khai phá dữ liệu.

Giới thiệu chung

Mục đích: Tạo các phím tắt, lập chương trình

rsam tạo, quản lý và tùy biến phím tắt

Cài đặt từ Github do gói lệnh install.github () từ

1
library(devtools)

1
2
3
library(devtools)
install_github("yonicd/rsam")
library(rsam)

Sau khi cài đặt package rsam thì ở mục Addins

Để thay đổi cách gán phím tắt :

1
2
3
4
5
6
keys <- KEYS$`left command/window key` + KEYS$shift + KEYS$l

rsam::set_shortcut(fn = 'rsam::lla1',shortcut = keys )

#if the binding already has a shortcut mapped to it `overide` must be TRUE
set_shortcut(fn = 'blogdown::serve_site',shortcut = key+ KEYS$`2`, overide = TRUE)

Nếu phím tắt đã từng tồn lại, tùy biến overide=TRUE sẽ vô hiệu hóa phím tắt trước đó và kích hoạt phím tắt thông qua rsam

Muốn gỡ bỏ phím tắt thì dùng câu lệnh :

1
rm_shortcut(fn = 'blogdown::serve_site')

1
Chú ý khi dùng rsam thì pipline (%>%) sẽ bị tạm thời vô hiệu hóa.

Ví dụ cụ thể để chạy 1 block lệnh bằng phím tắt Command+Shift+L+1

lla = Limited Liability Addins

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
library(rsam)
rsam()
rsam_fn_1=function(){
knitr::knit(input =paste0("_posts/",file[i]),
            output = paste0("_posts/",format(Sys.Date(),
                                             format="%Y-%m-%d"),"-",
                            substr(file[i], 1, nchar(file[i])-3),"md"))
}


rsam_fn_2=function(){
  print(my_doc, target = paste0("docx/example",
                                format(Sys.Date(),format="%d%b%y"),
                                ".docx"))
}

Khi lệnh fn_1 và fn_2 được định nghĩa, mỗi lần ấn tổ hợp phím tắt ở trên thì dù bất cứ ở cửa sổ nào thì toàn bộ câu lệnh được gói (Wrap) trong fn_ sẽ được tự động chạy.

-> Ý nghĩa việc này giúp tiết kiệm đáng kể thời gian thao tác chạy câu lệnh, đặc biệt là khi dùng thao tác với knitr, ggplot

Bên cạnh đó, có thể tùy chỉnh lại các phím tắt có trên Addins bằng cách định nghĩa lại các phím thích hợp thông qua

1
as.data.frame(fetch_addins()) 
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
                Package                            Name
1          addinmanager                   Addin manager
2            addinslist           Browse RStudio addins
3              bookdown                    Preview Book
4              bookdown                Input LaTeX Math
5                  Cite                            Cite
6                  citr                Insert citations
7                 clipr              Value to clipboard
8                 clipr             Output to clipboard
9          colourpicker              Plot Colour Helper
10         colourpicker                   Colour Picker
11                 covr Calculate package test coverage
12            datapasta                Paste as tribble
13            datapasta                 Paste as vector
14            datapasta      Paste as vector (vertical)
15            datapasta             Paste as data.frame
16               ggedit                          ggedit
17        ggThemeAssist          ggplot Theme Assistant
18           hrbraddins               Refresh .Renviron
19           hrbraddins                    Bare Combine
20           hrbraddins                       Join Rows
21           hrbraddins                     Tweet Share
22           hrbraddins                   Twitter Rant!
23           listviewer                        jsonedit
24           mischelper                Misc - View list
25           mischelper              Misc - Unwrap text
26           mischelper       Misc - Clip to data frame
27           mischelper        Misc - Flip windows path
28           mischelper                  Misc - Time it
29           mischelper           Misc - microbenchmark
30           mischelper         Misc - Render RMarkdown
31           mischelper           Misc - Format console
32           mischelper               Misc - View str()
33           mischelper          Misc - View data frame
34            questionr                 Levels recoding
35            questionr                 Levels ordering
36            questionr          Numeric range dividing
37              radiant                         Radiant
38              radiant                  Update Radiant
39               remedy                        Backtick
40               remedy                            Bold
41               remedy                           Chunk
42               remedy                      Chunksplit
43               remedy                              H1
44               remedy                              H2
45               remedy                              H3
46               remedy                              H4
47               remedy                              H5
48               remedy                              H6
49               remedy                           Image
50               remedy                         Italics
51               remedy                           LaTeX
52               remedy                            List
53               remedy                           Right
54               remedy                          Strike
55               remedy                           Table
56               remedy                             Url
57               remedy                        Xaringan
58               remedy                         Youtube
59               reprex                Render reprex...
60               reprex                Reprex selection
61        rhandsontable               Edit a Data Frame
62                 rsam                            lla1
63                 rsam                            lla2
64                 rsam                            lla3
65 RStudioConsoleRender               Render in console
66              shinyjs                   Colour Picker
67        snippetsaddin                      Insert %>%
68        snippetsaddin                   Convert slash
69        snippetsaddin                      Copy value
70        taskscheduleR   Schedule R scripts on Windows
71       wordcountaddin                      Word count
72       wordcountaddin                     Readability
73              WrapRmd                        Wrap Rmd
                                                                                                       Description
1                                                                                   Addin to maintain other addins
2                                                                       Discover and install useful RStudio addins
3                                                               Run bookdown::serve_book() to live preview a book.
4                                                                Input math expressions via the MathQuill library.
5                                                                    Helps insert bibtex citation in Rmd documents
6                                                                                       Inserts Markdown citations
7                                             Copies the results of a selected expression to the\nsystem clipboard
8                                      Copies the console output of a selected expression to\nthe system clipboard
9                                                                  Interactively pick colours to use in your plot.
10                                                                                 Lets you easily select colours.
11                                Calculates the package test coverage and opens a\nreport, using `covr::report()`
12                                        Pastes a table from the clipboard to the editor as a\ntribble definition
13     Pastes data from the clipboard to the editor as\ncharacter vector, formatted horizontally on a single line.
14 Pastes data from the clipboard to the editor as\ncharacter vector, formatted vertically, one element per\nline.
15                                     Pastes a table from the clipboard to the editor as a\ndata.frame definition
16                                                               Edit ggplot layers aesthetics and theme elements.
17                                                                                     Customize your ggplot theme
18                     Refreshes the in-memory environment variables from\n~/.Renviron without requiring a restart
19                                    Turns a selected comma-separated list of strings into\na base::c() statement
20                                                                       Join a selected set of rows into one line
21                                                                  Share the active RStudio source tab on Twitter
22                                             Make it easier to annoy followers and reinforce one's\nentitlement.
23                                                                                         View a list in jsonedit
24                                                           Select a list, view it with listviewer in viewer pane
25                Remove unneeded hard line breaks of text in\nclipboard, then paste into current cursor position.
26                 read clipboard, convert csv into data frame, open\ndata, write markdown table back to clipboard
27                                      convert "\\" in clipboard to "/", then paste into\ncurrent cursor position
28                                                             microbenchmark selected code with 1 runs in console
29                                                            microbenchmark selected code with 10 runs in console
30                                                                          Render RMarkdown in global environment
31                                                                       Format console input and output to script
32                                                                          Render str() output in html with style
33                                                                              Open selected data frame in Viewer
34                                                     Interactively generate code for a variable levels\nrecoding
35                                                   Interactively generate code for a variable levels\nreordering
36                                       Interactively generate code for dividing the range of\na numeric variable
37                                                                                                   Start Radiant
38                                                                            Update Radiant to the latest version
39                                                                                       Backtick selected word(s)
40                                                                                          Embolden selected text
41                                                                                            Chunk script or file
42                                                                                     Split chunk into two chunks
43                                                                         Convert selected text into an h1 header
44                                                                         Convert selected text into an h2 header
45                                                                         Convert selected text into an h3 header
46                                                                         Convert selected text into an h4 header
47                                                                         Convert selected text into an h5 header
48                                                                         Convert selected text into an h6 header
49                                                                    Convert selected path into an embedded image
50                                                                                         Italicize selected text
51                                                                      Convert the selected text in inline LaTeX.
52                                                                    Convert selected text into an unordered list
53                                                                       Copy selected text (or line) to the right
54                                                                                     Strikethrough selected text
55                                                                                         Insert a markdown table
56                                                                                Convert selected text into a url
57                                                                               xaringan pull left and pull right
58                                                             Convert selected text into a markdown youtube frame
59                                          Run `reprex::reprex()` to prepare a reproducible\nexample for sharing.
60                                                                           Prepare reprex from current selection
61                                                                                Interactively edit a data frame.
62                                         Wrap any global objects in rsam_fn_1() and use this\naddin to run them.
63                                         Wrap any global objects in rsam_fn_2() and use this\naddin to run them.
64                                         Wrap any global objects in rsam_fn_3() and use this\naddin to run them.
65                                                           Renders the current RMarkdown document in the console
66                                                                                 Lets you easily select colours.
67                                                                             Inserts pipe at the cursor position
68                                                                             switches the orientation of slashes
69                                                 copies value of the object under the cursor into the\nclipboard
70                                                Use Windows task scheduler to schedule your R scripts\n(Windows)
71                                         Counts words and characters (excluding code chunks,\ninline code, etc.)
72                                     Computes readability statistics (excluding code\nchunks, inline code, etc.)
73                                 Wrap selected R Markdown text but don't insert lines\nbreaks into inline R code
                 Binding Interactive                                   Key
1          addin_manager        true           addinmanager::addin_manager
2        addinslistAddin        true           addinslist::addinslistAddin
3             serve_book        true                  bookdown::serve_book
4              mathquill        true                   bookdown::mathquill
5                   cite        true                            Cite::cite
6        insert_citation        true                 citr::insert_citation
7           clipr_result       false                   clipr::clipr_result
8           clipr_output       false                   clipr::clipr_output
9        plotHelperAddin        true         colourpicker::plotHelperAddin
10     colourPickerAddin        true       colourpicker::colourPickerAddin
11          addin_report       false                    covr::addin_report
12         tribble_paste       false              datapasta::tribble_paste
13          vector_paste       false               datapasta::vector_paste
14 vector_paste_vertical       false      datapasta::vector_paste_vertical
15              df_paste       false                   datapasta::df_paste
16           ggeditAddin        true                   ggedit::ggeditAddin
17    ggThemeAssistAddin        true     ggThemeAssist::ggThemeAssistAddin
18      refresh_renviron       false          hrbraddins::refresh_renviron
19          bare_combine       false              hrbraddins::bare_combine
20             join_rows       false                 hrbraddins::join_rows
21           tweet_share       false               hrbraddins::tweet_share
22             rantAddin        true                 hrbraddins::rantAddin
23         jsoneditAddin       false             listviewer::jsoneditAddin
24             view_list       false                 mischelper::view_list
25                unwrap       false                    mischelper::unwrap
26             clip_2_df       false                 mischelper::clip_2_df
27     flip_windows_path       false         mischelper::flip_windows_path
28               time_it       false                   mischelper::time_it
29             benchmark       false                 mischelper::benchmark
30            render_rmd       false                mischelper::render_rmd
31        format_console       false            mischelper::format_console
32          render_addin       false              mischelper::render_addin
33               view_df       false                   mischelper::view_df
34                  irec        true                       questionr::irec
35                iorder        true                     questionr::iorder
36                  icut        true                       questionr::icut
37               radiant        true                      radiant::radiant
38        update_radiant        true               radiant::update_radiant
39             backtickr       false                     remedy::backtickr
40                 boldr       false                         remedy::boldr
41                chunkr       false                        remedy::chunkr
42           chunksplitr       false                   remedy::chunksplitr
43                   h1r       false                           remedy::h1r
44                   h2r       false                           remedy::h2r
45                   h3r       false                           remedy::h3r
46                   h4r       false                           remedy::h4r
47                   h5r       false                           remedy::h5r
48                   h6r       false                           remedy::h6r
49                imager       false                        remedy::imager
50              italicsr       false                      remedy::italicsr
51                latexr       false                        remedy::latexr
52                 listr       false                         remedy::listr
53                rightr       false                        remedy::rightr
54               striker       false                       remedy::striker
55                tabler       false                        remedy::tabler
56                  urlr       false                          remedy::urlr
57             xaringanr       false                     remedy::xaringanr
58              youtuber       false                      remedy::youtuber
59          reprex_addin        true                  reprex::reprex_addin
60      reprex_selection       false              reprex::reprex_selection
61             editAddin        true              rhandsontable::editAddin
62                  lla1        true                            rsam::lla1
63                  lla2        true                            rsam::lla2
64                  lla3        true                            rsam::lla3
65       renderInConsole        true RStudioConsoleRender::renderInConsole
66     colourPickerAddin        true            shinyjs::colourPickerAddin
67           insert.pipe       false            snippetsaddin::insert.pipe
68            flip.slash       false             snippetsaddin::flip.slash
69             copy.data       false              snippetsaddin::copy.data
70    taskschedulerAddin        true     taskscheduleR::taskschedulerAddin
71            text_stats        true            wordcountaddin::text_stats
72           readability        true           wordcountaddin::readability
73        wrap_rmd_addin       false               WrapRmd::wrap_rmd_addin
                                                                                     libpath
1          C:/Users/utilisateur/Documents/R/R-3.4.1/library/addinmanager/rstudio/_addins.dcf
2            C:/Users/utilisateur/Documents/R/R-3.4.1/library/addinslist/rstudio/_addins.dcf
3              C:/Users/utilisateur/Documents/R/R-3.4.1/library/bookdown/rstudio/_addins.dcf
4              C:/Users/utilisateur/Documents/R/R-3.4.1/library/bookdown/rstudio/_addins.dcf
5                  C:/Users/utilisateur/Documents/R/R-3.4.1/library/Cite/rstudio/_addins.dcf
6                  C:/Users/utilisateur/Documents/R/R-3.4.1/library/citr/rstudio/_addins.dcf
7                 C:/Users/utilisateur/Documents/R/R-3.4.1/library/clipr/rstudio/_addins.dcf
8                 C:/Users/utilisateur/Documents/R/R-3.4.1/library/clipr/rstudio/_addins.dcf
9          C:/Users/utilisateur/Documents/R/R-3.4.1/library/colourpicker/rstudio/_addins.dcf
10         C:/Users/utilisateur/Documents/R/R-3.4.1/library/colourpicker/rstudio/_addins.dcf
11                 C:/Users/utilisateur/Documents/R/R-3.4.1/library/covr/rstudio/_addins.dcf
12            C:/Users/utilisateur/Documents/R/R-3.4.1/library/datapasta/rstudio/_addins.dcf
13            C:/Users/utilisateur/Documents/R/R-3.4.1/library/datapasta/rstudio/_addins.dcf
14            C:/Users/utilisateur/Documents/R/R-3.4.1/library/datapasta/rstudio/_addins.dcf
15            C:/Users/utilisateur/Documents/R/R-3.4.1/library/datapasta/rstudio/_addins.dcf
16               C:/Users/utilisateur/Documents/R/R-3.4.1/library/ggedit/rstudio/_addins.dcf
17        C:/Users/utilisateur/Documents/R/R-3.4.1/library/ggThemeAssist/rstudio/_addins.dcf
18           C:/Users/utilisateur/Documents/R/R-3.4.1/library/hrbraddins/rstudio/_addins.dcf
19           C:/Users/utilisateur/Documents/R/R-3.4.1/library/hrbraddins/rstudio/_addins.dcf
20           C:/Users/utilisateur/Documents/R/R-3.4.1/library/hrbraddins/rstudio/_addins.dcf
21           C:/Users/utilisateur/Documents/R/R-3.4.1/library/hrbraddins/rstudio/_addins.dcf
22           C:/Users/utilisateur/Documents/R/R-3.4.1/library/hrbraddins/rstudio/_addins.dcf
23           C:/Users/utilisateur/Documents/R/R-3.4.1/library/listviewer/rstudio/_addins.dcf
24           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
25           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
26           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
27           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
28           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
29           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
30           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
31           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
32           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
33           C:/Users/utilisateur/Documents/R/R-3.4.1/library/mischelper/rstudio/_addins.dcf
34            C:/Users/utilisateur/Documents/R/R-3.4.1/library/questionr/rstudio/_addins.dcf
35            C:/Users/utilisateur/Documents/R/R-3.4.1/library/questionr/rstudio/_addins.dcf
36            C:/Users/utilisateur/Documents/R/R-3.4.1/library/questionr/rstudio/_addins.dcf
37              C:/Users/utilisateur/Documents/R/R-3.4.1/library/radiant/rstudio/_addins.dcf
38              C:/Users/utilisateur/Documents/R/R-3.4.1/library/radiant/rstudio/_addins.dcf
39               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
40               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
41               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
42               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
43               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
44               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
45               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
46               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
47               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
48               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
49               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
50               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
51               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
52               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
53               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
54               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
55               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
56               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
57               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
58               C:/Users/utilisateur/Documents/R/R-3.4.1/library/remedy/rstudio/_addins.dcf
59               C:/Users/utilisateur/Documents/R/R-3.4.1/library/reprex/rstudio/_addins.dcf
60               C:/Users/utilisateur/Documents/R/R-3.4.1/library/reprex/rstudio/_addins.dcf
61        C:/Users/utilisateur/Documents/R/R-3.4.1/library/rhandsontable/rstudio/_addins.dcf
62                 C:/Users/utilisateur/Documents/R/R-3.4.1/library/rsam/rstudio/_addins.dcf
63                 C:/Users/utilisateur/Documents/R/R-3.4.1/library/rsam/rstudio/_addins.dcf
64                 C:/Users/utilisateur/Documents/R/R-3.4.1/library/rsam/rstudio/_addins.dcf
65 C:/Users/utilisateur/Documents/R/R-3.4.1/library/RStudioConsoleRender/rstudio/_addins.dcf
66              C:/Users/utilisateur/Documents/R/R-3.4.1/library/shinyjs/rstudio/_addins.dcf
67        C:/Users/utilisateur/Documents/R/R-3.4.1/library/snippetsaddin/rstudio/_addins.dcf
68        C:/Users/utilisateur/Documents/R/R-3.4.1/library/snippetsaddin/rstudio/_addins.dcf
69        C:/Users/utilisateur/Documents/R/R-3.4.1/library/snippetsaddin/rstudio/_addins.dcf
70        C:/Users/utilisateur/Documents/R/R-3.4.1/library/taskscheduleR/rstudio/_addins.dcf
71       C:/Users/utilisateur/Documents/R/R-3.4.1/library/wordcountaddin/rstudio/_addins.dcf
72       C:/Users/utilisateur/Documents/R/R-3.4.1/library/wordcountaddin/rstudio/_addins.dcf
73              C:/Users/utilisateur/Documents/R/R-3.4.1/library/WrapRmd/rstudio/_addins.dcf
           Shortcut
1              <NA>
2              <NA>
3              <NA>
4              <NA>
5  Ctrl+Shift+Alt+R
6  Ctrl+Shift+Alt+C
7        Ctrl+Alt+C
8              <NA>
9              <NA>
10             <NA>
11             <NA>
12       Ctrl+Alt+T
13             <NA>
14             <NA>
15             <NA>
16             <NA>
17             <NA>
18             <NA>
19       Ctrl+Alt+B
20             <NA>
21             <NA>
22             <NA>
23             <NA>
24             <NA>
25             <NA>
26             <NA>
27             <NA>
28             <NA>
29             <NA>
30       Ctrl+Alt+M
31             <NA>
32             <NA>
33             <NA>
34     Ctrl+Shift+R
35     Ctrl+Shift+O
36             <NA>
37             <NA>
38             <NA>
39             <NA>
40           Ctrl+B
41             <NA>
42             <NA>
43       Ctrl+Alt+1
44       Ctrl+Alt+2
45       Ctrl+Alt+3
46       Ctrl+Alt+4
47       Ctrl+Alt+5
48             <NA>
49       Ctrl+Alt+P
50           Ctrl+I
51             <NA>
52           Ctrl+/
53 Ctrl+Shift+Right
54             <NA>
55     Ctrl+Shift+T
56             <NA>
57             <NA>
58             <NA>
59             <NA>
60             <NA>
61             <NA>
62       Ctrl+Alt+L
63       Ctrl+Alt+Z
64             <NA>
65             <NA>
66             <NA>
67             <NA>
68             <NA>
69             <NA>
70             <NA>
71            Alt+W
72             <NA>
73       Ctrl+Alt+W

Clipr - copy dữ liệu sang bộ nhớ đệm clipboard

Với thủ thuật này, không cần phải xuất/lưu biến bảng biểu hay kết quả phân tích sang dạng csv hay excel mà chỉ cần dùng addins này thì toàn bộ output/biến sẽ được lưu vào có thể paste trực tiếp trên word (kết quả phân tích) hoặc excel (ưu tiên với bảng dữ liệu). Có thể gán phím tắt cho tác vụ này ở đây mình dùng là ctrl+alt+C để copy giá trị nội dung của 1 biến (value) sau khi thao tác bôi đen dòng biến hoặc dòng lệnh chứa biến đó

Đặc biệt có thể copy được biến thay đổi bởi pipline ( %>% )

Datapasta

Paste dữ liệu dưới dạng bảng Trible,tible dạng vector dạng data.frame…. Hữu dụng

1
devtools::install_github(datapasta)

Remedy - hỗ trợ soạn thảo trên Rmardown

Thao tác chèn link, kiểu chữ, styling, Heading… được gán các phím tắt quen thuộc như Ctrl+B = bold, Ctrl+I = Italic….

1
install.packages(remedy)

Wrapmd - tự động cắt chữ xuống

Phím tắt

…. to be continued!

Status (On projet Sept 2018)


Creative Commons License

©Canhgiacduoc(2017)

Trong bài này, các kỹ năng xử lý văn bản sẽ được tổng hợp dần dần trong quá trình xây dự văn bản dài (manuscript thesis hoặc xây dựng 1 cuốn sách lớn về kỹ thuật)

Mục đích

  • Giảm thiểu hạn chế của Word MS mà vẫn tận dụng được những ưu điểm vượt trội (trực quan, tương tác, dễ vi xử lý..) của phần mềm này.
  • Do trong quá trình làm việc với file lớn, lỗi rất dễ xảy ra -> cần phải “chia để trị” nhằm giảm thiểu rủi ro và hiệu suất làm việc (giảm thời gian mở file, làm việc trên mây, dễ quản lý)
  • Khi kết nối file, tính năng trích dẫn zotero, caption vẫn được bảo tồn. các Style mà thuộc tính giống nhau thì sẽ được bảo tồn.

Tùy biến Styles trong Words

Modify Styles advanced

  • Phím tắt - Styling văn bản trong vòng 1 tích tắc
  • Copy Styles từ 1 file nguồn sang 1 file word khác hoặc đặt nó trong mặc định

Sử dụng Macros (tương thích với Window tốt)

  • Macros chạy khá tốt trên window, tuy nhiên trên Mac tính năng này còn nhiều hạn chế
  • Mục đích chính là xử lý thao tác được lặp lại, lưu lại thao tác và dùng phím tắt để chạy trong vòng 1 nốt nhạc
  • Khi áp dụng styling trên 1 nhóm văn bản cần dùng chung 1 định dạng, macros nên và cần áp dụng để xử lý hậu kỳ trước khi kết nối các văn bản Word rời rạc để tránh xung đột định dạng
  • Một số kỹ năng hữu dụng giúp xử lý hàng loạt hình ảnhbảng (đã áp dụng thành công khi xuất ra từ file trên R-Markdown): lựa chọn tất cả các bảng trong 1 văn bản (để áp dụng styling cho bảng hàng loạt), chọn tất cả hình ảnh và resize (hiệu chỉnh) kích thước được ấn định

Trích dẫn TLTK chuyên nghiệp bằng Zotero thay cho tính năng nghèo nàn sẵn có trên Word

Vấn đề này sẽ nói trong 1 bài cụ thể

Caption table and figure

Có nhiều video hướng dẫn chi tiết về vấn đề này trên youtube (Gõ “Caption table” trên Youtube là có 1 loạt bài chi tiết)

Ưu điểm: bảng và hình được cho 1 số sequence thứ tự theo vị trí của bảng/hình trong văn bản và số này được tự động sắp lại khi thêm hoặc thay đổi cấu trúc văn bản Nhược điểm: Khi ghép nối phải refeshing lại và 1 vài trường hợp phải Indexing lại, Đặt caption theo chương mục nếu không based trên Heading Style thì nhiều trường hợp muốn thể hiện tên Chapter trên Caption hơi phức tạp.

Indexing

Officer - gói lệnh xử lý Word MS trên nền tảng R

Ứng dụng của lệnh trong gói này giúp hiểu sâu thêm về cấu trúc văn bản. Giúp kết nối các văn bản Word mà không cần phải cài thêm phần mềm phụ trợ (JAVA) như cac gói lệnh khác Ưu điểm: Nhanh, trực quan, dễ sử dụng, có thể chèn trực tiếp 1 ảnh/bảng biểu vào 1 vị trí xác định trong văn bản (cursor), Thêm được tính năng chèn hình với kích thước cho tùy biến; Chỉnh sửa hàng loạt và áp dụng vòng lặp, sử dụng giao thoa được với các Package khác để tận dụng sức mạnh của R.

Xem bài hướng dẫn chi tiết trên web…


Creative Commons License

©Canhgiacduoc(2017)

Xử lý ảnh dùng R và gói lệnh Magick - P1: Cơ bản

Thông thường R dùng rất phổ biến để phân tích và biểu diễn số liệu, tuy nhiên R có thể làm được rất nhiều thao tác xử lý ảnh và quan trong nhất là tính “reproductive” (lặp lại) đặc trưng khi dùng R. Thông qua các ví dụ về xử lý ảnh, R có thể thay thế hoàn hảo cho các phần mềm xử lý ảnh thông dùng ở một vài thao tác, tạo ảnh động và các thuật toán sâu hơn dựa trên database là dữ liệu ảnh.

Giới thiệu chung và setup

Cài đặt magick package Version 1.9 trên CRAN :

1
install.packages(magick)

Thông tin về gói lệnh và cú pháp:

1
library(magick); ?magick

library(magick)
?magick
dl_from_dropbox <- function(x, key) {
  require(RCurl)
  bin <- getBinaryURL(paste0("https://dl.dropboxusercontent.com/s/", key, "/", x), ssl.verifypeer = FALSE)
  con <- file(x, open = "wb")
  writeBin(bin, con)
  close(con)
  message(noquote(paste(x, "read into", getwd())))                        
}

Đọc và ghi ảnh

example

Time-to-onset Signal

Time-to-onset Signal

Time-to-onset Signal

Other example

Đọc ảnh procedure

```r
# gg=mtcars %>% ggplot(aes(disp,mpg)) +geom_point(aes(col=as.factor(cyl)))  #      sdf   adf

# upload_get_link_image_dropbox(gg,"image-test1.png")
```

test 2

Link tới 1 file html

…. to be continued!

Link1

Link1

Status (On projet Aug 2018)


Creative Commons License

©Canhgiacduoc(2017)

1.Kết nối dữ liệu data 2010-2016 - remove duplicate

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# drug1016.Edited %>% filter(Group=="AntibacterialSystematic") %>% filter(ATC=="") 
# 0 rows -> OK no drug withou ATC code in antibiotic


betalactam1016=drug1016.Edited %>%mutate(GrPhar=substr(ATC,1,4),
                                         Year=substr(as.character(Year.ID),1,4)) %>%
  filter(Group=="AntibacterialSystematic") %>%
  filter(GrPhar %in% c("J01D","J01C")) %>% unique()

          
          id=betalactam1016$Year.ID
          # #To return ALL MINUS ONE duplicated values:
          # id[duplicated(id)]
          # 
          # #To return ALL duplicated values by specifying fromLast argument:
          # id[duplicated(id) | duplicated(id, fromLast=TRUE)]
          #Yet another way to return ALL duplicated values, using %in% operator:
          id.trung1016= unique(id[id %in% unique(id[duplicated(id)])])

2.List report combination with betalactamase

1
2
3
4
5
6
7
8
9
10
# elimination of coprescription 2 suspected betaclam

betalactam1016 %>% filter(Year.ID %in% id.trung1016) %>% View()

id.betalactamse1016=c(  201098,201096,   2010556,  20101100,  20101355,  20101374,  20101399,  20101401,  
                    20101406,  20101438,  20101443,  20101457,  20101492
                   
) %>% as.character() 

betalactam1016 %>% filter(Year.ID %in% id.betalactamse1016)   #  loai do 2 betalactam tren 1 thuoc 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
## # A tibble: 27 x 6
##        ATC            Drug Year.ID                   Group GrPhar  Year
##      <chr>           <chr>   <dbl>                   <chr>  <chr> <chr>
##  1 J01CA01      ampicillin   2e+05 AntibacterialSystematic   J01C  2010
##  2 J01DD01       cefotaxim   2e+05 AntibacterialSystematic   J01D  2010
##  3 J01CG01       sulbactam   2e+05 AntibacterialSystematic   J01C  2010
##  4 J01CA01      ampicillin   2e+05 AntibacterialSystematic   J01C  2010
##  5 J01CG01       sulbactam   2e+05 AntibacterialSystematic   J01C  2010
##  6   J01CR acid clavulanic   2e+06 AntibacterialSystematic   J01C  2010
##  7 J01CA04     amoxicillin   2e+06 AntibacterialSystematic   J01C  2010
##  8   J01CR acid clavulanic   2e+07 AntibacterialSystematic   J01C  2010
##  9 J01CA04     amoxicillin   2e+07 AntibacterialSystematic   J01C  2010
## 10   J01CR acid clavulanic   2e+07 AntibacterialSystematic   J01C  2010
## # ... with 17 more rows
1
id.betalactamse1016[-2] # loai gia tri thu 2 tuong duong bao cao 201096
1
2
##  [1] "201098"   "2010556"  "20101100" "20101355" "20101374" "20101399"
##  [7] "20101401" "20101406" "20101438" "20101443" "20101457" "20101492"
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
betalactam1016=betalactam1016 %>% mutate(
  Drug=replace(Drug,Year.ID=="201098","ampicilin/sulbactam"),
  Drug=replace(Drug,Year.ID=="2010556","amoxicilin/acid clavulanic"), 
  Drug=replace(Drug,Year.ID=="20101100","amoxicilin/acid clavulanic"),
  Drug=replace(Drug,Year.ID=="20101355","amoxicilin/acid clavulanic"),
  
  Drug=replace(Drug,Year.ID=="20101374","amoxicilin/acid clavulanic"),
  Drug=replace(Drug,Year.ID=="20101399","amoxicilin/acid clavulanic"),
  Drug=replace(Drug,Year.ID=="20101401","amoxicilin/acid clavulanic"),
  Drug=replace(Drug,Year.ID=="20101406","amoxicilin/acid clavulanic"),
  Drug=replace(Drug,Year.ID=="20101438","cefoperazon/sulbactam"),
  Drug=replace(Drug,Year.ID=="20101443","amoxicilin/acid clavulanic"),
  Drug=replace(Drug,Year.ID=="20101457","amoxicilin/acid clavulanic"),
  Drug=replace(Drug,Year.ID=="20101492","piperacillin/tazobactam")) %>% 
  
  mutate(Drug=str_replace_all(Drug,"cilin","cillin")) %>%
  
  select(-ATC) %>% unique()

     # betalactam1016 %>% View

id=betalactam1016$Year.ID     
ds.trung.final1016=betalactam1016 %>% filter(Year.ID %in%  id[id %in% unique(id[duplicated(id)])],
                                     !Year.ID %in% id.betalactamse[-2])%>% unique() # 181


betalactam.nodup1016=betalactam1016%>% filter(!Year.ID%in%ds.trung.final$Year.ID) %>% unique()



betalactam.nodup.casenoncase.1016=betalactam.nodup1016 %>%left_join(
  d1016.2 %>% select(Year,Year.ID=mabc,Age,Sex,Case,Mortality)
) %>% 
  mutate( Drug=replace(Drug,Year.ID=="20147153","imipenem/cilastatin")) %>% filter(Case %in% 0:1) %>% 
  mutate(
  Drug=replace(Drug,Drug=="amipicillin/sulbactam","ampicillin/sulbactam"),
   Drug=replace(Drug,Drug=="cefotaxime","cefotaxim"),
  Drug=replace(Drug,Drug=="cefpirome","cefpirom"),
  Drug=replace(Drug,Drug=="ceftriaxone","ceftriaxon"),
  Drug=replace(Drug,Drug=="amoxicillin/clavunanic","amoxicillin/acid clavulanic"),
  
  Drug=replace(Drug,Drug=="benzathin penicillin g","benzathine benzylpenicillin"),
  Drug=replace(Drug,Drug=="penicillin g","benzylpenicillin"),
  Drug=replace(Drug,Drug=="penicillin v","phenoxymethylpenicillin")
  
  	 
  
  
  )%>% left_join(read_excel("Betalactam ATC code update.xlsx") %>% select(Drug,ATC)) %>% 
  mutate(subgroup.betalactam=substr(ATC,1,5))
1
betalactam.nodup.casenoncase.1016 %>% group_by(Drug) %>% tally(sort=T)  %>% unique()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
## # A tibble: 54 x 2
##                           Drug     n
##                          <chr> <int>
##  1                   cefotaxim  3115
##  2                  ceftriaxon  1561
##  3                  ceftazidim  1192
##  4                   cefuroxim   703
##  5                 amoxicillin   701
##  6                 cefoperazon   405
##  7                   cefalexin   371
##  8                  ampicillin   278
##  9 amoxicillin/acid clavulanic   271
## 10        ampicillin/sulbactam   193
## # ... with 44 more rows
1
betalactam.nodup.casenoncase.1016 %>% group_by(GrPhar) %>% tally(sort=T)  %>% unique()
1
2
3
4
5
## # A tibble: 2 x 2
##   GrPhar     n
##    <chr> <int>
## 1   J01D  8892
## 2   J01C  1904
1
betalactam.nodup.casenoncase.1016 %>% group_by(subgroup.betalactam) %>% tally(sort=T)  %>% unique()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
## # A tibble: 11 x 2
##    subgroup.betalactam     n
##                  <chr> <int>
##  1               J01DD  6824
##  2               J01CA  1054
##  3               J01DC   975
##  4               J01DB   735
##  5               J01CR   614
##  6               J01DE   220
##  7               J01CE   160
##  8               J01DH   138
##  9               J01CF    74
## 10               J01CG     1
## 11                J01D     1

3.Subgroup signals : J01DD and J01CE

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
subgroup.betalactam.list=betalactam.nodup.casenoncase.1016%>%group_by(subgroup.betalactam) %>%
  tally(sort=T) %>% filter(subgroup.betalactam!="J01D") #%>% View ()


for (i in 1:nrow(subgroup.betalactam.list)){
  temp=betalactam.nodup.casenoncase.1016 %>%   filter(., grepl(subgroup.betalactam.list[i,]$subgroup.betalactam, subgroup.betalactam))
  varname <- paste(subgroup.betalactam.list[i,]$subgroup.betalactam )
  
  betalactam.nodup.casenoncase.1016[[varname]]=with(betalactam.nodup.casenoncase.1016,if_else(Year.ID%in% temp$Year.ID,1,0))
  
}

OR.subgroup.betalactam=NULL

for (i in 1:nrow(subgroup.betalactam.list)){

    formula.i=lapply(subgroup.betalactam.list[i,]$subgroup.betalactam,
                   function(var) formula(paste0('Case~',var),env=globalenv()))
  OR.subgroup.betalactam=rbind(OR.subgroup.betalactam,
     betalactam.nodup.casenoncase.1016 %>% 
    select(Year,Age,Sex,Case,matches(subgroup.betalactam.list[i,]$subgroup.betalactam)) %>% 
    glm(formula=formula.i[[1]],family=binomial(link="logit")) %>% OR95()%>% 
    tibble::rownames_to_column() %>% filter(between(row_number(), 2, n()))  
  )
  
  }

OR.subgroup.betalactam.n=betalactam.nodup.casenoncase.1016 %>% filter(Year.ID %in% subset(betalactam.nodup.casenoncase.1016,Case==1)$Year.ID) %>% group_by(subgroup.betalactam) %>% tally(sort=T) %>% left_join(
  OR.subgroup.betalactam ,  by = c("subgroup.betalactam" = "rowname") 
)


OR.subgroup.betalactam.n %>% print()
1
2
3
4
5
6
7
8
9
10
11
12
## # A tibble: 9 x 5
##   subgroup.betalactam     n    OR lower upper
##                 <chr> <int> <dbl> <dbl> <dbl>
## 1               J01DD  1280  1.30  1.17  1.44
## 2               J01DB   143  1.16  0.95  1.39
## 3               J01CA   124  0.61  0.50  0.73
## 4               J01DC   113  0.60  0.49  0.73
## 5               J01CR   100  0.92  0.73  1.14
## 6               J01DE    49  1.37  0.98  1.87
## 7               J01CE    43  1.76  1.22  2.48
## 8               J01DH    20  0.80  0.48  1.26
## 9               J01CF     9  0.65  0.30  1.25
1
2
3
4
5
6
7
8
9
10
OR.subgroup.betalactam.n %>% unique() %>% 
  mutate(subgroup.betalactam=paste0(subgroup.betalactam,' (n=',n,")")) %>%
  arrange(n) %>%  mutate(subgroup.betalactam = factor(subgroup.betalactam, subgroup.betalactam)) %>% 
ggplot(  aes(x=subgroup.betalactam, y=OR, ymin=lower, ymax=upper)) +
  geom_errorbar() + 
  geom_point(aes(shape=if_else(lower>1,T,F))) + #,col="blue",shape=5
  geom_hline(yintercept=1, lty=2) +  # add a dotted line at x=1 after flip
  coord_flip() +  # flip coordinates (puts labels on y axis)
  xlab("Drug") + ylab("Adjusted OR (95% CI)") +
  theme_bw()  # use a white background

«««< HEAD:_posts/2018-05-30-Betalactam analysis stratification Notebook.md GGPlot plot2 of chunk unnamed-chunk-4 ======= GGPlot plot of chunk unnamed-chunk-4

1522bad2ad157ed42d6809c938b743194108ad6a:_posts/2018-05-30-Betalactam analysis stratification Notebook.md

3.1.Signal of subgroup.cepha

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
for (i in 1:length(subgroup.cepha)){
  temp=cepha %>%   filter(., grepl(subgroup.cepha[i], cephagroup))
  varname <- paste(subgroup.cepha[i] )
  
  d1016.3[[varname]]=with(d1016.3,if_else(mabc%in% temp$Year.ID,1,0))

  
}

OR.table.subgroupcepha.1016=NULL

for (i in 1:length(subgroup.cepha)){

    formula.i=lapply(subgroup.cepha[i],
                   function(var) formula(paste0('Case~',var),env=globalenv()))
  OR.table.subgroupcepha.1016=rbind(OR.table.subgroupcepha.1016,
     d1016.3 %>% #filter(ATC!="J01D") %>% 
    select(Year,Age,Sex,Case,matches(subgroup.cepha[i])) %>% 
    glm(formula=formula.i[[1]],family=binomial(link="logit")) %>% OR95()%>% 
    tibble::rownames_to_column() %>% filter(between(row_number(), 2, n()))  
  )
  
}
OR.table.subgroupcepha.1016 %>% print()
1
2
3
4
5
6
##   rowname  OR lower upper
## 1   J01DD 2.3  2.12   2.4
## 2   J01DB 1.8  1.52   2.1
## 3   J01DC 1.1  0.95   1.3
## 4   J01DH 1.1  0.76   1.6
## 5   J01DE 2.3  1.80   3.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
OR.table.subgroupcepha.1016.n=cepha %>% left_join(d1016.3 %>% select(Year.ID=mabc,Case) %>% filter(Case==1))%>% filter(Case==1) %>% group_by(cephagroup) %>% tally() %>% filter(cephagroup!="J01D") %>% 
    left_join(OR.table.subgroupcepha.1016 ,by = c("cephagroup" = "rowname")) 



OR.table.subgroupcepha.1016.n %>% unique() %>% mutate(cephagroup=paste0(cephagroup,'(n=',n,")")) %>% 
  arrange(n) %>%  mutate(cephagroup = factor(cephagroup, cephagroup)) %>% 
ggplot(  aes(x=cephagroup, y=OR, ymin=lower, ymax=upper)) +
  geom_errorbar() + 
  geom_point(aes(shape=if_else(lower>1,T,F))) + #,col="blue",shape=5
  geom_hline(yintercept=1, lty=2) +  # add a dotted line at x=1 after flip
  coord_flip() +  # flip coordinates (puts labels on y axis)
  xlab("cephagroup") + ylab("Adjusted ROR (95% CI)") +
  theme_bw()  # use a white background

plot of chunk unnamed-chunk-5

1
2
3
4
5
6
OR.table.subgroupcepha.1016.n %>%  
  arrange(desc(n)) %>%  mutate(OR=round(OR,2),
                               lower=round(lower,2),
                               upper=round(upper,2)) %>%
  
  write.csv2("OR.table.subgroupcepha.1016.n.csv",row.names=F)

4.C3G vs other cephalosporins: subgroup.betalactam

1
2
3
4
5
6
7
8
9
10
11
x=betalactam.nodup.casenoncase.1016$Drug
x=x %>% stringr::str_replace_all(c(" "),".") %>% 
   stringr::str_replace_all(c("/"),".")
betalactam.nodup.casenoncase.1016$Drug=x
 
 
cepha.strata1=betalactam.nodup.casenoncase.1016 %>% filter(GrPhar=="J01D")
  # mutate(cephagroup=substr(ATC,1,5)) %>% 
  # filter(ATC!="J01D") 

cepha.strata1 %>%group_by(subgroup.betalactam) %>% tally(sort=T) %>% print() 
1
2
3
4
5
6
7
8
9
## # A tibble: 6 x 2
##   subgroup.betalactam     n
##                 <chr> <int>
## 1               J01DD  6823
## 2               J01DC   975
## 3               J01DB   735
## 4               J01DE   220
## 5               J01DH   138
## 6                J01D     1
1
2
3
4
5
6
cepha.strata.C3G=betalactam.nodup.casenoncase.1016 %>% filter(subgroup.betalactam=="J01DD")

d1016.strata.C3G=d1016.3 %>% select(Year,Year.ID=mabc,Age,Sex,Mortality,Case) %>%
  filter(Year.ID%in%cepha.strata.C3G$Year.ID)

cepha.strata.C3G.list=cepha.strata.C3G %>% group_by(Drug) %>% tally(sort=T)

5 Strata cepha third geneation : d1016.strata.C3G

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
d1016.strata.C3G[["C3G"]]=""

for (i in 1:nrow(cepha.strata.C3G.list)){
  temp=cepha.strata.C3G %>%   filter(., grepl(cepha.strata.C3G.list[i,]$Drug, Drug))
  varname <- paste(cepha.strata.C3G.list[i,]$Drug )
  
  d1016.strata.C3G[[varname]]=with(d1016.strata.C3G,if_else(Year.ID%in% temp$Year.ID,1,0))
  
  d1016.strata.C3G=d1016.strata.C3G %>% mutate(C3G=if_else(Year.ID%in% temp$Year.ID,varname,C3G))
}

OR.cepha.strata.C3G=NULL

for (i in 1:nrow(cepha.strata.C3G.list)){

    formula.i=lapply(cepha.strata.C3G.list[i,]$Drug,
                   function(var) formula(paste0('Case~',var),env=globalenv()))
  OR.cepha.strata.C3G=rbind(OR.cepha.strata.C3G,
     d1016.strata.C3G %>% 
    select(Year,Age,Sex,Case,matches(cepha.strata.C3G.list[i,]$Drug)) %>% 
    glm(formula=formula.i[[1]],family=binomial(link="logit")) %>% OR95()%>% 
    tibble::rownames_to_column() %>% filter(between(row_number(), 2, n()))  
  )
  
  }

OR.cepha.strata.C3G.n=cepha.strata.C3G %>% filter(Year.ID %in% subset(d1016.strata.C3G,Case==1)$Year.ID) %>% group_by(Drug) %>% tally(sort=T) %>% left_join(
  OR.cepha.strata.C3G ,  by = c("Drug" = "rowname") 
)


OR.cepha.strata.C3G.n %>% print()
1
2
3
4
5
6
7
8
9
10
11
12
## # A tibble: 9 x 5
##                    Drug     n    OR lower upper
##                   <chr> <int> <dbl> <dbl> <dbl>
## 1             cefotaxim   557  0.90 0.795  1.02
## 2            ceftriaxon   307  1.07 0.931  1.24
## 3            ceftazidim   252  1.20 1.027  1.40
## 4           cefoperazon    88  1.26 1.017  1.56
## 5 cefoperazon.sulbactam    31  1.36 0.894  2.03
## 6            ceftizoxim    28  1.00 0.649  1.49
## 7               cefixim    10  0.25 0.122  0.44
## 8            cefpodoxim     5  0.36 0.125  0.81
## 9              cefdinir     2  0.51 0.081  1.78
1
2
3
4
5
6
7
8
9
OR.cepha.strata.C3G.n %>% unique() %>% mutate(Drug=paste0(Drug,'(n=',n,")")) %>% 
  arrange(n) %>%  mutate(Drug = factor(Drug, Drug)) %>% 
ggplot(  aes(x=Drug, y=OR, ymin=lower, ymax=upper)) +
  geom_errorbar() + 
  geom_point(aes(shape=if_else(lower>1,T,F))) + #,col="blue",shape=5
  geom_hline(yintercept=1, lty=2) +  # add a dotted line at x=1 after flip
  coord_flip() +  # flip coordinates (puts labels on y axis)
  xlab("Drug") + ylab("Adjusted ROR (95% CI)") +
  theme_bw()  # use a white background

plot of chunk unnamed-chunk-7

1
2
3
4
5
6
7
# 
# OR.cepha.strata.C3G.n %>%  
#   arrange(desc(n)) %>%  mutate(OR=round(OR,2),
#                                lower=round(lower,2),
#                                upper=round(upper,2)) %>%
#   
#   write.csv2("OR.cepha.strata.C3G.n.csv",row.names=F)

6. Risk relatifs between C3G with cefotaxim as refrence

1
2
3
4
5
## Réordonnancement de d1016.strata.C3G$C3G
d1016.strata.C3G$C3G <- factor(d1016.strata.C3G$C3G, levels=c("cefotaxim", "ceftriaxon", "ceftazidim", "cefixim", "cefoperazon", "ceftizoxim", "cefpodoxim", "cefoperazon.sulbactam", "cefdinir", "cefodoxim", "cefetamet", "ceftriaxon.sulbactam"))


d1016.strata.C3G %>% group_by(C3G) %>% tally(sort=T)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## # A tibble: 12 x 2
##                      C3G     n
##                   <fctr> <int>
##  1             cefotaxim  3115
##  2            ceftriaxon  1561
##  3            ceftazidim  1192
##  4           cefoperazon   405
##  5               cefixim   181
##  6            ceftizoxim   149
##  7 cefoperazon.sulbactam   130
##  8            cefpodoxim    65
##  9              cefdinir    19
## 10  ceftriaxon.sulbactam     4
## 11             cefodoxim     1
## 12             cefetamet     1
1
2
3
4
5
6
7
8
9
10
11
12
d1016.strata.C3G %>% select(Year,Age,Sex,Case,C3G) %>% 
  mutate(Case=as.factor(Case)) %>% 
    glm(formula=Case~Year+Age+Sex+C3G,family=binomial(link="logit")) %>% OR95()%>% 
    tibble::rownames_to_column() %>% filter(between(row_number(), 9, n())) %>% 

ggplot(  aes(x=rowname, y=OR, ymin=lower, ymax=upper)) +
  geom_errorbar() + 
  geom_point(aes(shape=if_else(lower>1,T,F))) + #,col="blue",shape=5
  geom_hline(yintercept=1, lty=2) +  # add a dotted line at x=1 after flip
  coord_flip(ylim=c(0,3)) +  # flip coordinates (puts labels on y axis)
  xlab("C3G diferent risks") + ylab("Adjusted ROR (95% CI)") +
  theme_bw()  # use a white background

plot of chunk unnamed-chunk-8

Các vấn đề khó khăn khi xử lý CSDL Việt Nam

Ở Việt Nam, thống kê y tế là một rào cản khá lớn. Hiện tại các nghiên cứu muốn công bố trên thế giới cần phải tiến hành rà soát lại TLTK ở Việt Nam. Anh Hoàng Anh cho rằng mình phải bắt chước Trung QUốc là phải để các nghiên cứu bản địa (local) là rất quan trong bên cạnh các bài báo quốc tế. Như vậy trong bài báo có thể không nói nhưng trong bài Luận Văn phải nói được và bàn luận sâu thêm về vấn đề

Dược sỹ báo cáo nhiều hơn có tiềm ẩn nguy cơ gì không

Dược sỹ thuộc khoa Cận Lâm sàng do đó thường đóng vai trò trung gian gửi báo cáo nhiều hơn là người phát hiện báo cáo như ở nước Pháp. Nếu số lượng dược sỹ mà báo cáo tăng lên thì dự báo cơ cấu báo cáo sẽ vẫn bị lệch nhiều vì nhận thức của các nhóm đối tượng báo cáo khác nhau.

Nguyên nhân giải thích cho việc báo cáo ở VN chỉ có kháng sinh và thuốc trị lao

Báo cáo ADR khởi nguồn từ chương trình lao và chương trình y tế quốc gia PHP có gắn bó mật thiết và quan hệ 2 chiều với trung tâm ADR. báo cáo lao đóng vai trò quan trọng trong cơ cấu báo cáo ở VN.

Sốc phản vệ và tín hiệu an toàn thuốc của Việt Nam

  • SPV : làm thêm 2016 để có dữ liệu 7 năm….
  • Thuốc báo cáo trong CSDL chủ yếu là KS phổ rộng : câu chuyện đằng sau đó là gì
    • Thuốc bảo hiểm chủ yếu là KS betalactam :ở VN là câu chuyện cephalosporin thế hệ 3.
    • Ngoài bản chất thuốc còn có yếu tố khác có thể dẫn tới tai biến : Tốc độ tiêm truyền (liệu có phải chỉ có ở VN không, các nước tham chiếu có gặp vấn đề tương tự không)
    • Propofol ở pháp báo cáo nhiều nhất có thể giải thích đc không? Ở Pháp có hội gây mê và có các báo cáo liên tục liên quan tới SPV trong gây mê.

SJS/TEN ở Việt Nam có gì khác so với Pháp

1
Ở các nước khá allopurinol ít báo cáo hơn do được sử dụng theo chỉ định, còn ở VN câu chuyện allopurinol là bị sử dụng quá mức và lạm dụng chỉ định nên báo cáo (có vẻ) là nhiều hơn dẫn tới ADR nhiều hơn,

Ví dụ

Tables

Header1 Header2 Header3
cell1 cell2 cell3
cell4 cell5 cell6
cell1 cell2 cell3
cell4 cell5 cell6
Foot1 Foot2 Foot3eeeeē eeiï 2222222222222222sdfhuhfloauhfluahdfiuhlsdiufhsduhf## Tables
Header1 Header2 Header3
cell1 cell2 cell3
cell4 cell5 cell6
cell1 cell2 cell3
cell4 cell5 cell6
Foot1 Foot2 Foot3eeeeē eeiï 2222222222222222sdfhuhfloauhflua hdfiuhlsdiufhsduhfhafygsadfygaskdjfhgkajshg fdkjhasgdh

Conclusion

Vậy, việc thiết kế form và cải tiến hình thức và quy trình theo hướng này tỏ ra có nhiều ưu điểm và rất có tiềm năng áp dụng trong thực tế ở Việt Nam (Pháp hiện đang áp dụng kiểu báo cáo này).

Status (On projet Dec 2017)


Creative Commons License

©Canhgiacduoc(2017)