Debian Codegraph @

R/zzz.R

raw
1 # Copyright (C) Tal Galili
2 #
3 # This file is part of dendextend.
4 #
5 # dendextend is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # dendextend is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # A copy of the GNU General Public License is available at
16 # http://www.r-project.org/Licenses/
17
18
19
20 # https://stackoverflow.com/questions/10325231/when-writing-my-own-r-package-i-cant-seem-to-get-other-packages-to-import-corr
21 #' @importFrom viridis viridis
22
23 #' @import datasets
24
25
26
27
28
29 # Add myself to github:
30 # http://www.r-bloggers.com/rstudio-and-github/
31
32 # git remote add origin https://github.com/talgalili/dendextend.git
33 # git config remote.origin.url [email protected]:talgalili/dendextend.git
34 # git pull -u origin master
35 # git push -u origin master
36
37 # https://nathanj.github.io/gitguide/tour.html
38 # add "[email protected]:talgalili/dendextend.git"
39
40 # if the RStudio buttons are greyed out, then run the following in git shell:
41 # git push -u origin master
42 # source: http://www.r-bloggers.com/things-i-forget-pushpull-greyed-out-in-rstudio/
43 # this updates \\.git\\config with the following lines:
44 # [branch "master"]
45 # remote = origin
46 # merge = refs/heads/master
47
48
49 .onLoad <- function(libname, pkgname) {
50 # Thanks for Romain: https://stackoverflow.com/questions/4369334/first-lib-idiom-in-r-packages
51
52 # adding and removing menus from the Rgui when loading and detaching the library
53 # setHook(packageEvent("installr", "attach"), {function(pkgname, libpath) {add.installr.GUI()} } )
54 # setHook(packageEvent("dendextend", "detach"), {function(pkgname, libpath) {remove_dendextend_options()} } )
55
56 # set default options for dendextend
57 setHook(packageEvent("dendextend", "onLoad"), {
58 function(pkgname, libpath) {
59 assign_dendextend_options()
60 }
61 })
62
63 # Does NOT work!
64 # remove_dendextend_options is currently an empty function. In the future, it should
65 # remove default options for dendextend when unloading
66 setHook(packageEvent("dendextend", "onUnload"), {
67 function(pkgname, libpath) {
68 remove_dendextend_options()
69 }
70 })
71 setHook(packageEvent("dendextend", "detach"), {
72 function(pkgname, libpath) {
73 remove_dendextend_options()
74 }
75 })
76
77 # dendextend::dendextend_options()
78 }
79
80 # menus are added and removed as needed: !!
81
82
83 .onAttach <- function(lib, pkg, ...) {
84 ####
85 ### I decided to not use the following code since it will
86 ### always give a "masked" warning when loading
87 ### dendextend. But it IS an issue...
88 ####
89 # if ape is installed on this computer, it will be loaded FIRST!
90 # This way I make sure to not have "rotate" masked by {ape}
91 # (they would still work though)
92
93 # this would solve it, but it is not a "nice" way to do it...
94 # if("ape" %in% .packages(all.available = TRUE)) {
95 # library("ape", pos = which(search() %in% "package:dendextend")+1,
96 # warn.conflicts = FALSE,
97 # quietly = TRUE)
98 # }
99
100 # The above line causes problems such as: 'library' or 'require' call not declared from: 'ape'
101
102 # search()
103 # unloadNamespace(ape")
104 # unloadNamespace("dendextend")
105 # require("dendextend", warn.conflicts = TRUE)
106 # require("dendextend", warn.conflicts = FALSE)
107 # but it makes sure that "dendextend" does not "Depends" on ape"...
108
109 # move some functions to the "options" so that they would later be overridden.
110 # create_dendextend_options()
111
112 # details in dendextend_options.R
113 # assign_dendextend_options()
114
115 packageStartupMessage(dendextendWelcomeMessage())
116
117 # assign_dendextendRcpp_to_dendextend()
118 }
119
120
121
122
123 dendextendWelcomeMessage <- function() {
124 # library(utils)
125
126 # paste("\n",
127 # "Welcome to dendextend version ", utils::packageDescription("dendextend")$Version, "\n",
128 # "\n",
129 # "Type ?dendextend to access the overall documentation and\n",
130 # "browseVignettes(package = 'dendextend') for the package vignette.\n",
131 # "You can execute a demo of the package via: demo(dendextend)\n",
132 # "\n",
133 # "More information is available on the dendextend project web-site:\n",
134 # "https://github.com/talgalili/dendextend/\n",
135 # "\n",
136 # "Contact: <[email protected]>\n",
137 # "Suggestions and bug-reports can be submitted at: https://github.com/talgalili/dendextend/issues\n",
138 # "\n",
139 # "\t\t\tTo suppress this message use:\n",
140 # "\t\t\tsuppressPackageStartupMessages(library(dendextend))\n",
141 # sep="")
142 #
143 paste0(
144 "\n",
145 "---------------------\n",
146 "Welcome to dendextend version ", utils::packageDescription("dendextend")$Version, "\n",
147 # "\n",
148 "Type citation('dendextend') for how to cite the package.\n",
149 "\n",
150 "Type browseVignettes(package = 'dendextend') for the package vignette.\n",
151 "The github page is: ",
152 "https://github.com/talgalili/dendextend/\n",
153 "\n",
154 "Suggestions and bug-reports can be submitted at: https://github.com/talgalili/dendextend/issues\n",
155 "You may ask questions at stackoverflow, use the r and dendextend tags: \n\t https://stackoverflow.com/questions/tagged/dendextend\n",
156 "\n",
157 "\tTo suppress this message use: ", "suppressPackageStartupMessages(library(dendextend))\n",
158 "---------------------\n"
159 )
160 }
161
162
163
164 # Defined so to support with_mocked_bindings usage in tests
165 requireNamespace <- NULL
166
167
168 # using "zzz.r" like in devtools...
169
170 # When adding new files, make sure they are listed in DESCRIPTION:
171 # Collate:
172 # 'create.global.library.r'
173 # 'install.r'
174 # 'updateR.r'
175
176
177
178
179 # library(dendextend)
180 # environmentIsLocked(as.environment("package:dendextend"))
181 # lockEnvironment(env=as.environment("package:dendextend"), bindings = FALSE)
182 # lockEnvironment(env=as.environment("package:dendextend"), bindings = TRUE)
183
184
185 # IMPORTANT NOTICE: this will add Collate to the DESCRIPTION file, and if any new r file is added - it will need to be updated.
186 # Collate:
187 # + 'create.global.library.r'
188 # + 'install.r'
189 # + 'updateR.r'
190 # + 'zzz.r'
191
192
193 ############
194 ## OLD
195 # Steps:
196 # http://r.789695.n4.nabble.com/vignettes-problems-with-PDF-compaction-td4664909.html
197 # 1) install gs - http://www.ghostscript.com/download/gsdnld.html
198 # 2) find where it is, and update R_GSCMD:
199 # Sys.setenv(R_GSCMD="C:\\Program Files\\gs\\gs9.10\\bin\\gswin64c.exe")
200 # Sys.setenv(R_GSCMD="C:\\Program Files\\gs\\gs9.14\\bin\\gswin64c.exe")
201 # Sys.setenv(R_GSCMD="D:\\temp\\qpdf-5.1.2\\bin\\qpdf.exe")
202 # Sys.getenv("R_GSCMD")
203 # 3) Check that it works:
204 # system2(Sys.getenv("R_GSCMD"), args="--version")
205 # 4) use:
206 # library(tools)
207 # tools::compactPDF("inst\\doc\\dendextend-tutorial.pdf", gs_quality="printer")
208 # tools::compactPDF("inst\\doc\\dendextend-tutorial.pdf",
209 # qpdf = "D:\\temp\\qpdf-5.1.2\\bin\\qpdf.exe", gs_cmd = "C:\\Program Files\\gs\\gs9.14\\bin\\gswin64c.exe")
210 #### tools::compactPDF("inst\\doc\\dendextend-tutorial.pdf", gs_quality="ebook")
211 #### tools::compactPDF("inst\\doc\\dendextend-tutorial.pdf", gs_quality="screen")
212 #### tools::compactPDF("vignettes\\dendextend-tutorial.pdf")
213 ### compacted 'dendextend-tutorial.pdf' from 964Kb to 737Kb
214 #### tools::compactPDF("vignettes\\dendextend-tutorial.pdf", gs_quality="ebook")
215
216 # For checking:
217 # 1) get qpdf
218 # http://sourceforge.net/projects/qpdf/files/
219 # 2) put it somewhere
220 # 3) set R_QPDF
221 # Sys.setenv(R_QPDF="C:\\Rtools\\qpdf-5.1.1\\bin\\qpdf.exe")
222 # Sys.which(Sys.getenv("R_QPDF", "qpdf"))
223
224 # Also, make sure to add:
225 # options(repos=c("http://cran.rstudio.com", "http://www.stats.ox.ac.uk/pub/RWin" ))
226 # to D:\R\R-devel\etc\Rprofile.site
227
228 ##############
229
230
231
232
233
234
235
236 ##########
237 ##########
238 ##########
239 ##########
240 ## NEW
241 # How to deal with compression:
242 # 1) Download the latest qpdf: http://sourceforge.net/projects/qpdf/files/ (and place it somewhere)
243 # 2) Install gs - http://www.ghostscript.com/download/gsdnld.html
244 # 3) Run the following:
245
246 # tools::compactPDF("inst\\doc\\dendextend-tutorial.pdf",
247 # qpdf = "C:\\Program Files (x86)\\qpdf-5.1.2\\bin\\qpdf.exe",
248 # gs_cmd = "C:\\Program Files\\gs\\gs9.14\\bin\\gswin64c.exe",
249 # gs_quality="ebook")
250
251 ##########
252 ##########
253 ##########
254
255
256
257 # https://stat.ethz.ch/pipermail/r-help/2010-September/251194.html
258 # tools::showNonASCII( readLines("vignettes\\FAQ.Rmd"))
259 #
260
261
262
263
264
265 ####### Cool stuff to add:
266 # library(devtools)
267 # use_code_of_conduct()
268 # use_cran_badge()
269 # use_coveralls()
270 # #
271
272
273
274 # install.packages("C:\\Dropbox\\aaaa good R code\\AA - My packages\\dendextend_1.0.0.tar.gz", repos = NULL, type="source")
275
276 #
277 # # Run once:
278 # shell('set PATH=%PATH%;"C:\\Program%20Files%20(x86)\\Git\\bin"', intern = TRUE)
279 # shell("echo %PATH% ", intern= TRUE)
280 #
281 # system('set PATH=%PATH%;C:\\xampp\\php')
282 #
283 #
284 #
285 # # Creating a changelog using git
286 # First make sure git is in the path. Run the
287 # following using cmd.exe, as admin:
288 # setx PATH "C:\\Program Files (x86)\\Git\\bin"
289 #
290 # Then - run the script to create the ChangeLog before shipping the package.
291 # # https://stackoverflow.com/questions/10330425/how-do-i-export-a-git-log-to-a-text-file
292 # # https://stackoverflow.com/questions/3523534/good-ways-to-manage-a-changelog-using-git
293 # # http://www.commandlinefu.com/commands/view/12420/generate-a-change-log-with-git
294 # shell("git log --decorate > ChangeLog", intern = T)
295
296 # Modify it using: http://git-scm.com/book/en/Git-Basics-Viewing-the-Commit-History
297 # https://stackoverflow.com/questions/9007181/custom-log-format-omits-newline-at-end-of-output
298 # shell('git log --graph --stat --date=iso > ChangeLog', intern = TRUE)
299 # use this:
300 # shell('git log --graph --stat --date=short --pretty=format:"%ad(%an) %s |%h" > ChangeLog', intern = TRUE)
301 #
302 # system.PATH()
303 # shell("path")
304
305
306 # shell("echo %PATH% ", intern= TRUE)
307 # library(rmarkdown)
308 # rmarkdown::render("NEWS",clean = TRUE,output_format = "html_document")
309
310
311
312
313
314
315
316
317 # when a function is renamed, its document in man must be removed - otherwise it may cause problems with the built check (it will try to run the code in the example, and will fail.)
318 # When all is done, run:
319 # library(devtools)
320 # check()
321 # browseURL(tempdir())
322 ### http://www.rstudio.com/ide/docs/packages/build_options
323 #
324 # check(build_args="--no-build-vignettes --no-manual", args = "--no-examples --no-build-vignettes --no-manual", cran = FALSE, cleanup = FALSE)
325 # devtools::check(build_args="--no-build-vignettes --no-manual", args = " --no-build-vignettes --no-manual", cran = FALSE, cleanup = FALSE)
326 # check(build_args="--no-build-vignettes --no-manual", args = "--no-build-vignettes --no-manual", cran = FALSE, cleanup = FALSE)
327 # check(build_args="--no-build-vignettes ", args = "--no-build-vignettes", cran = FALSE, cleanup = FALSE)
328 # devtools::check(args="--as-cran")
329 # devtools::check("C:/Dropbox/aaaa good R code/AA - My packages/dendextend", args="--as-cran")
330 # Thanks to: https://stackoverflow.com/questions/10017702/r-cmd-check-options-for-more-rigorous-testing-2-15-0
331
332
333 # Adding github actions:
334 # https://www.tidyverse.org/blog/2022/06/actions-2-0-0/
335
336 # spelling::spell_check_package()
337 # shell('git log --graph --stat --date=short --pretty=format:"%ad(%an) %s |%h" > ChangeLog', intern = TRUE)
338 # For linux:
339 # system('git log --graph --stat --date=short --pretty=format:"%ad(%an) %s |%h" > ChangeLog', intern = TRUE)
340 # pkgdown::build_site(run_dont_run = FALSE)
341 # pkgdown::build_home()
342 # pkgdown::build_news()
343 # pkgdown::build_site()
344 # pkgdown::build_articles()
345 # devtools::check_win_release()
346 # devtools::check_win_devel()
347 # release()