MangoTheCat/cyclocomp

How can i pass the variable in quote i.e cyclocomp(quote(variable)) or cyclocomp_q(variable)

pawan-panwar opened this issue · 3 comments

variable <- for (var in seq) expr
cyclocomp_q(variable) / cyclocomp(quote(variable))

the above method taking variable as a string not its value.

How can i pass the file instead of string in cyclocomp method.

You mean this?

for1 <- quote(for (var in seq) expr)
cyclocomp::cyclocomp(for1)
#> [1] 3
for2 <- quote(for (var in seq) for (var2 in seq2) expr)
cyclocomp::cyclocomp(for2)
#> [1] 6

Created on 2022-12-12 with reprex v2.0.2

Yes but its not working in case of Rscript arguments i.e. Rscript script.R "for (var in seq) expr"
Content in script.R -

library(cyclocomp)
args <- commandArgs(trailingOnly = TRUE)
cyclocomp(args)
@gaborcsardi thanks in advance !!

You need to parse() the script into an R expression:

script <- "

library(somepackage)

call_some_function()

for (var in seq) {
  for (var2 in seq2) {
    do_something
  }
}
"

writeLines(script, script_file <- tempfile())

expr <- parse(script_file)
cyclocomp::cyclocomp(expr)
#> [1] 6

Created on 2022-12-13 with reprex v2.0.2