2016-10-24 6 views
0

私はこのコードをif..elsif..elseステートメントの中に別のテーブルをkableで印刷するようにしました。私のデータフレームを使用してKableはif..elsif ... elseステートメント内にテーブルを表示しません

```{r} 
    if (sum(df_final2$change)!=0 && nrow(df_final[is.na(df_final$PEH.1),])!=0) { 
     cat("The new peptides are:\n") 
     kable(df_peptides_spectra2) 
     cat("Decreased or increased:\n") 
     kable(df_final3) 
    } else if (sum(df_final2$change)==0 && nrow(df_final[is.na(df_final$PEH.1),])!=0) { 
     cat("The new peptides are:") 
     kable(df_peptides_spectra2) 
     cat("The rest peptides are the same.") 
    } else if (sum(df_final2$change)!=0 && nrow(df_final[is.na(df_final$PEH.1),])==0) { 
     cat("The are not new peptides:\n")  
     cat("Decreased or increased:\n") 
     kable(df_final3) 
    } else 
     cat("The number of peptides are the same\n") 
``` 

、条件を満たした状態でオプション2であるので、私はこれを持っていると予想:ものの

cat("The new peptides are:") 
kable(df_peptides_spectra2) 
cat("The rest peptides are the same.") 

、私の出力は、任意のテーブルずに、これです。 :

The new peptides are: 
The rest of peptides are the same. 

これを修正する方法はありますか?私は各印刷呼び出しの後に改行を追加しようとしましたが(R: why kable doesn't print inside a for loop?)、私は同じ問題を抱えています。お使いの再現性のある例では

```{r} 



    df <- structure(list(ID = structure(c(1L, 2L, 3L, 4L, 5L), 
    .Label = c("1", "2", "3", "4" ,"5")), 
    sequence = structure(c(1L,2L, 3L, 4L, 5L), 
    .Label = c(" actgat "," atagattg ", " atatagag ", " atggggg ", " atgtagtt "), class = "factor"), 
    peptides = structure(c(1L, 2L, 3L, 4L, 5L), 
    .Label = c(" 54 ", " 84 ", " 32 ", " 36 ", "12"), 
    class = "factor"), n_project = structure(c(1L, 1L, 1L, 1L, 1L), 
    .Label = " project ", class = "factor")), .Names = c("ID", "sequence", "peptides", "n_project"), class = "data.frame", row.names = c(NA, -5L)) 



    if (0!=0 && (0)!=0) { 
     cat("The new peptides are:\n") 
     kable(df) 
     cat("Decreased or increased:\n") 
     kable(df) 
    } else if (10==10 && 2!=0) { 
     cat("The new peptides are:") 
     kable(df) 
     cat("The rest peptides are the same.") 
    } else if (10!=10 && 2!=0) { 
     cat("The are not new peptides:\n")  
     cat("Decreased or increased:\n") 
     kable(df) 
    } else 
     cat("The number of peptides are the same\n") 


``` 

答えて

2

、テーブルやを表示するprint(kable(df))を使用します。

ここでは、再現可能な例を持っています。

```{r, results='asis'} 

    cat("The new peptides are:\n") 
    print(kable(df)) 
    cat("\n") 
    cat("The rest peptides are the same.") 

--- 

enter image description here

+0

しかし、私はhtml形式でそれを持ってしたいと思います。私はそれがこれよりも見栄えが良いと思う。 – Enrique

+0

ありがとう!それは動作します! – Enrique

関連する問題