Skip to content

Commit

Permalink
Merge pull request #285 from nlmixr2/274-feature-request-piping-accep…
Browse files Browse the repository at this point in the history
…ts-strings

Piping should accept strings
  • Loading branch information
mattfidler committed Sep 22, 2022
2 parents 4a59fb1 + 0bddeb1 commit 3954abf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions R/piping.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@
} else if (inherits(.cur, "character") && !is.null(names(.cur))) {
.unlistedBrackets <- lapply(paste(names(.cur),"=", setNames(.cur, NULL)),
str2lang)
} else if (inherits(.cur, "character") && length(.cur) == 1) {
.unlistedBrackets <- try(str2lang(.cur), silent=TRUE)
if (inherits(.unlistedBrackets, "try-error")) {
stop("vectors and list need to named numeric expression", call.=FALSE)
}
if (identical(.unlistedBrackets[[1]], quote(`=`))) {
.unlistedBrackets[[1]] <- quote(`<-`)
}
.unlistedBrackets <- list(.unlistedBrackets)
} else {
stop("vectors and list need to named numeric expression", call.=FALSE)
}
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-ui-piping.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rxTest({
tv = 3
tcl = 10
eta.v+eta.cl~unfix(cor(sd(0.3,0.02,0.1)))
}), list(quote(-ka),
}, "tv10=3"), list(quote(-ka),
quote(tka <- 0.5),
quote(tv <- 3),
quote(tcl <- 10),
Expand All @@ -28,7 +28,8 @@ rxTest({
quote(eta.ka ~ 3),
quote(tv <- 3),
quote(tcl <- 10),
quote(eta.v + eta.cl ~ unfix(cor(sd(0.3, 0.02, 0.1))))))
quote(eta.v + eta.cl ~ unfix(cor(sd(0.3, 0.02, 0.1)))),
quote(tv10 <- 3)))

expect_equal(testPipeQuote(tka=0.5, {
tv = 3
Expand Down

0 comments on commit 3954abf

Please sign in to comment.