Skip to content

Commit 303f09c

Browse files
committed
update term help function to handle terms with and without arguments
fixes #87
1 parent dd1f1cd commit 303f09c

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
^.*\.Rproj$
22
^\.Rproj\.user$
3+
rsconnect
34
inst/shiny/rsconnect
45
inst/pics
56
inst/html
@@ -8,3 +9,4 @@ LICENSE
89
^\.travis\.yml$
910
^\.github$
1011
^cran-comments\.md$
12+
^CRAN-SUBMISSION$

inst/shiny/statnetWeb/global.R

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,26 @@ inlineSelectInput <- function(inputId, label, choices, ...) {
3434
lapply(choices, tags$option)))
3535
}
3636

37-
# create a list of unique term names
37+
# create a list of unique term names and arguments
3838
# allow searching by string -- set to NULL to get search by nw attributes
39+
# note not all terms have arguments, so pattern matching accomodates
40+
3941
splitargs <- function(string, nw){
4042
sink("NUL")
4143
allterms <- search.ergmTerms(search = string, net = nw)
4244
sink()
45+
46+
hasarg <- ifelse(
47+
grepl(pattern = "[^ ]\\(", allterms), 1, 0)
4348
ind1 <- regexpr(pattern = "\\(", allterms)
4449
ind2 <- regexpr(pattern = "\\)", allterms)
45-
termnames <- substr(allterms, start = rep(1, length(allterms)), stop = ind1 - 1)
46-
termargs <- substr(allterms, start = ind1, stop = ind2)
50+
51+
termnames <- substr(allterms,
52+
start = rep(1, length(allterms)),
53+
stop = ifelse(hasarg, ind1-1, ind1-2))
54+
termargs <- ifelse(hasarg,
55+
substr(allterms, start = ind1, stop=ind2),
56+
"")
4757
dups <- duplicated(termnames)
4858
termnames <- termnames[!dups]
4959
termargs <- termargs[!dups]

0 commit comments

Comments
 (0)