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

Do not display “NULL” functions in Rmarkdown output #1572

Closed
Biostat44 opened this issue Apr 19, 2019 · 3 comments
Closed

Do not display “NULL” functions in Rmarkdown output #1572

Biostat44 opened this issue Apr 19, 2019 · 3 comments
Labels
question
Milestone

Comments

@Biostat44
Copy link

@Biostat44 Biostat44 commented Apr 19, 2019

I want to print the results of two functions with Rmarkdown. These functions operate under certain conditions. If the conditions are not satisfied, the function returns NULL, but I don't want NULL to be written in the output of Rmarkdown. Can you help with this?
The sample code is given below.


title: "Untitled"
author: "Biostat44"
date: "19 Nisan 2019"
output: word_document

l=NROW(iris$Sepal.Length)

  
  if(l<=50){
    shapiro.test(x =iris$Sepal.Length )
  }else{
    return(NULL)
  }
  
  if(l>50){
   ks.test(x = iris$Sepal.Length,"pnorm")
  }else{
    return(NULL)
  }

l=NROW(iris$Sepal.Length)

if(l<=50){
shapiro.test(x =iris$Sepal.Length )
}else{
return(NULL)
}

NULL

if(l>150){
ks.test(x = iris$Sepal.Length,"pnorm")
}else{
return(NULL)
}

Warning in ks.test(x = iris$Sepal.Length, "pnorm"): ties should not be

present for the Kolmogorov-Smirnov test

One-sample Kolmogorov-Smirnov test

data: iris$Sepal.Length

D = 0.99999, p-value < 2.2e-16

alternative hypothesis: two-sided

@cderv
Copy link
Collaborator

@cderv cderv commented Apr 20, 2019

I think you can just to nothing

---
title: "Untitled"
author: "Biostat44"
date: "19 Nisan 2019"
output: html_document
---

```{r}
l = NROW(iris$Sepal.Length)


if(l <= 50){
  shapiro.test(x =iris$Sepal.Length )
}

if(l > 50){
  ks.test(x = iris$Sepal.Length,"pnorm")
}
```

This will only print the result of the second if. Rmarkdown will print everything that results of a chunk. You need to get a result in adequation with the printing part afterward. If results is NULL, it will print NULL, unless you deal with something like if is NULL then print nothing ("" or like here nothing as no result at all)

Also, for this kind of question, do not hesitate to ask on https://community.rstudio.com instead of Github Issue. There is a large community ready to help there and Github issue are more suited for issues with the 📦 or feature request.

Hope it helps.

@yihui yihui added this to the v1.13 milestone Apr 20, 2019
@yihui yihui added the question label Apr 20, 2019
@yihui
Copy link
Member

@yihui yihui commented Apr 20, 2019

@Biostat44 Please do not ignore the issue template next time. Thanks!

@yihui yihui closed this as completed Apr 20, 2019
@github-actions
Copy link

@github-actions github-actions bot commented Nov 3, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question
Projects
None yet
Development

No branches or pull requests

3 participants