44
44
.github_pattern ))))
45
45
}
46
46
47
- .github_repos <- gh :: gh(" /orgs/Funz/repos" ,.token = NA )
48
- if (length(.github_repos )== 0 ) .github_repos <- NA
47
+ # should blok at package install/lazy load if not connected: .github_repos <- gh::gh("/orgs/Funz/repos",.token=NA, per_page=100)
48
+ # if (length(.github_repos)==0)
49
+ .github_repos <- NA
49
50
50
51
# ########################### Models #################################
51
52
@@ -73,11 +74,12 @@ installed.Models <- function() {
73
74
# ' }
74
75
available.Models <- function (refresh_repo = F ) {
75
76
if (refresh_repo | any(is.na(.github_repos )))
76
- .env $ .github_repos <- gh :: gh(" /orgs/Funz/repos" ,.token = NA )
77
+ .github_repos <- jsonlite :: fromJSON(readLines(curl :: curl(" https://api.github.com/orgs/Funz/repos?per_page=100" ),warn = FALSE ))
78
+ # not working behind some proxy: gh::gh("/orgs/Funz/repos",.token=NA, per_page=100)
77
79
78
80
gsub(" plugin-" ," " ,
79
- unlist(lapply(.github_repos ,
80
- function (r ) {if (length(grep(" plugin-" ,r $ name ))> 0 ) r $ name else NULL })),
81
+ unlist(lapply(.github_repos $ name ,
82
+ function (r ) {if (length(grep(" plugin-" ,r ))> 0 ) r else NULL })),
81
83
fixed = T )
82
84
}
83
85
@@ -155,7 +157,7 @@ setup.Model <- function(model, edit.script=FALSE) {
155
157
attr(node ," command" ) <- normalizePath(script )
156
158
cplugin = file.path(FUNZ_HOME ," plugins" ," calc" ,paste0(model ," .cplugin.jar" ))
157
159
if (file.exists(cplugin ))
158
- attr(node ," cplugin" ) <- paste0(" file:/" ,normalizePath(cplugin ))
160
+ attr(node ," cplugin" ) <- paste0(" file:// " ,normalizePath(cplugin ))
159
161
}
160
162
if (isTRUE(node == " [ comment ]" )) {
161
163
node <- NA
@@ -169,7 +171,7 @@ setup.Model <- function(model, edit.script=FALSE) {
169
171
attr(node ," command" ) <- normalizePath(script )
170
172
cplugin = file.path(FUNZ_HOME ," plugins" ," calc" ,paste0(model ," .cplugin.jar" ))
171
173
if (file.exists(cplugin ))
172
- attr(node ," cplugin" ) <- paste0(" file:/" ,normalizePath(cplugin ))
174
+ attr(node ," cplugin" ) <- paste0(" file:// " ,normalizePath(cplugin ))
173
175
}
174
176
calculator.xml $ CALCULATOR [[i + 1 ]] <- node
175
177
names(calculator.xml $ CALCULATOR )[[i + 1 ]] <- " CODE"
@@ -233,14 +235,13 @@ install_github.Model <- function(model,force=F, edit.script=FALSE) {
233
235
# ' install.Model('Modelica')
234
236
# ' }
235
237
install.Model <- function (model ,force = F , edit.script = FALSE ) {
236
- if (file.exists(model ))
237
- install_file.Model(model , force , edit.script )
238
- else {
239
- if (model %in% available.Models())
240
- install_github.Model(model , force , edit.script )
241
- else
242
- stop(" Model " ,model ," is not available." )
243
- }
238
+ if (file.exists(model ) && ! dir.exists(model ))
239
+ try({install_file.Model(model , force , edit.script ); return ()})
240
+
241
+ if (model %in% available.Models())
242
+ install_github.Model(model , force , edit.script )
243
+ else
244
+ stop(" Model " ,model ," is not available." )
244
245
}
245
246
246
247
@@ -269,11 +270,12 @@ installed.Designs <- function() {
269
270
# ' }
270
271
available.Designs <- function (refresh_repo = F ) {
271
272
if (refresh_repo | any(is.na(.github_repos )))
272
- .env $ .github_repos <- gh :: gh(" /orgs/Funz/repos" ,.token = NA )
273
+ .github_repos <- jsonlite :: fromJSON(readLines(curl :: curl(" https://api.github.com/orgs/Funz/repos?per_page=100" ),warn = FALSE ))
274
+ # not working behind some proxy: gh::gh("/orgs/Funz/repos",.token=NA, per_page=100)
273
275
274
276
gsub(" algorithm-" ," " ,
275
- unlist(lapply(.github_repos ,
276
- function (r ) {if (length(grep(" algorithm-" ,r $ name ))> 0 ) r $ name else NULL })),
277
+ unlist(lapply(.github_repos $ name ,
278
+ function (r ) {if (length(grep(" algorithm-" ,r ))> 0 ) r else NULL })),
277
279
fixed = T )
278
280
}
279
281
@@ -347,12 +349,11 @@ install_github.Design <- function(design,force=F) {
347
349
# ' install.Design('GradientDescent')
348
350
# ' }
349
351
install.Design <- function (design ,force = F ) {
350
- if (file.exists(design ))
351
- install_file.Design(design , force )
352
- else {
353
- if (design %in% available.Designs())
354
- install_github.Design(design , force )
355
- else
356
- stop(" Design " ,design ," is not available." )
357
- }
352
+ if (file.exists(design ) && ! dir.exists(design ))
353
+ try({install_file.Design(design , force ); return ()})
354
+
355
+ if (design %in% available.Designs())
356
+ install_github.Design(design , force )
357
+ else
358
+ stop(" Design " ,design ," is not available." )
358
359
}
0 commit comments