1

I have some code in my RMarkdown file that I knit:

ifelse(Sys.info()[1]=="Linux",
       wdir <- "/path/1",
       wdir <- "/path/2")
setwd(wdir)

Except it's supposed to be silent. I've got it in a block with

```{r prepare.data,echo=F,warning=FALSE,message=FALSE,error=FALSE}

I don't want to generate any output from that, yet when I knit, I get this in the output:

##                                          sysname 
## "/path/1"

I've tried just that code snip in the console and it is generating that print output.

My Questions are: 1. Why is ifelse printing this output? 2. How can I avoid it?

Thanks!

0

1 Answer 1

2

Try wdir <- ifelse(Sys.info()[1]=="Linux", "/path/1", "/path/2"). The reason the output is printed is that if you don't assign the ifelse output to some variable, it will just print it on the screen. It is like writing a <- 1 + 2 vs 1 + 2.

Sign up to request clarification or add additional context in comments.

1 Comment

I meant to add, perhaps you got confused with the if..else.. structure which would not generate an output (as it is not a function like ifelse()). So if(Sys.info()[1] == "Linux") wdir <- "path/1" else wdir <- "path/2" would work too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.