Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pawan-panwar opened this issue Dec 12, 2022 · 3 comments

Comments

@pawan-panwar
Copy link

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.

@pawan-panwar pawan-panwar changed the title How can i pass the variable in cyclocomp(quote(variable)) or cyclocomp_q(variable) How can i pass the variable in quote i.e cyclocomp(quote(variable)) or cyclocomp_q(variable) Dec 12, 2022
@gaborcsardi
Copy link
Contributor

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

@pawan-panwar
Copy link
Author

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 !!

@gaborcsardi
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants