2017-07-25 840 views
1

當我在Rmarkdown中編寫下面的代碼塊時,它也會打印出結果。我只想運行並顯示代碼。在同一.Rmd文件這個knitr語法同樣適用其他的代碼塊...如何顯示和運行代碼,但不打印結果在Rmarkdown knitr

```{r import, results = "hide"} 

gs_ls() 

df <- gs_title("worlds-view-of-America") 

confInPres <- df %>% gs_read(ws = "Sheet1", range = cell_rows(1:38)) 

colnames(confInPres) <- paste("year", colnames(confInPres), sep = "_") 

colnames(confInPres)[1] <- "Country" 

confInTrump <- select(confInPres, Country, year_2017) 

favUS <- df %>% gs_read(ws = "Sheet2", range = cell_rows(1:38)) 
``` 

回答

2

看看here

如果要顯示代碼,請使用echo=TRUE

+0

當我添加這些'''{r import,message = FALSE,warning = FALSE}''除了'gs_ls()'調用之外,一切似乎都奏效。 – Tdebeus

+0

你期望它做什麼?它列出用戶可以在Google Sheets主屏幕中看到的電子表格,但由於您設置了「results = hide」,因此您不打印任何內容。如果您希望打印結果,則應該設置「results =」asis 「'並執行一些類似print(gs_ls())的操作。希望這可以幫助!請考慮接受我的答案,如果有的話。 – Florian

相關問題