A question when I am running my chunk in r markdown. The result will not be shown below but can be shown in the console

A question when I am running my chunk in r markdown. The result will not be shown below but can be shown in the console

As an example, when I run my chunk, usually all my results will be output below the chunk. But commands such as print(), head(), tail(), simply any command to manifest data will turn out to nothing. However, if I run it in the console, it does give me a proper outcome.

I had tried various ways to reset the output style in the "global options", but all approaches seem invalid. Does anyone know how to solve it?
BTW, I don't want my result to be shown in the console, but just let it be shown below my chunks.

When you're working with an R Markdown document or Notebook, you control whether or not that output is in the console or inline with the "Chunk Out ..." option,

Here's where you set that:


Control over how chunks appear when knited are handled by chunk options,
For a more complete explanation: Options - Chunk options and package options - Yihui Xie | 谢益辉

With global chunk options, Options - Chunk options and package options - Yihui Xie | 谢益辉


For example,

---
title: "reprex"
output: pdf_document
---

```{r include=FALSE}

print("1")

```

```{r include=TRUE}

print("2")

```

should produce a doc that looks like,


After considering all that, if you still have this problem, could you walk us through it with a minimal reproducible example (kinda just guessing at this point)?

1 Like

Hi sorry, I didn't mean that I had a problem at outputting to a doc.

For an example like this, after I ran a chunk, there will be an ouput display below my chunk, and it seems all commands respond perfectly, such as summary(), names(), etc...
But if I type head(), tail(), print(), any command to display an object or data.frame, nothing will display. However if I run the whole project, it will be output in the document without a problem.

I just want to preview my data while I'm running a line or a chunk instead of running the whole file.~

BTW, even plotting is fine, but just enable to preview object

have'nt get a reply. so just quikly refresh my question so it won't dissapear~~

Hi,
I think I have the same problem although as far as I can see only concerns displaying data.frames. I think the problem (at least in my case) has to do with LOCALE settings or encodings in some way. (I have a lot to learn about such matters so bear with me if I express myself poorly...)
What I have found is that the problem only appears when my Rstudio-project (which holds my code) resides in a folder named with any special character (like the Swedish å, ä, ö). If I move the whole project folder to a folder without special characters it works fine.
I have tested it with a simple example that should display a table of a data.frame inline in the Rmarkdown/Rnotebook document. Sure enough. it does when in a non-special-character-named folder but not in a folder named with any of the Swedish å, ä or ö.

Here's what my notebook editor would look like if the project resides in a special character folder (and running the code):

---
title: "R Notebook"
output: html_notebook
---


```{r}
data.frame(a=1:10, b=11:20)
```


```{r}
a <- c(1, 4, 3)
a
```
[1] 1 4 3

The a object is shown inline but not the data.frame

Unfortunately I don't know how to show inline outputs such as tables (data.frames) using formatted code in my post so I'll have to show the situation when in a non-special-character folder as a picture, sorry:

As you can see now the data.frame is properly shown as a table inline. The only difference between the two situations is that the RStudio project resides in a special character folder (with an å in its name) or not.
By the way, the html-notebook-document generated have the same problems, it is not just in the editor.

I realise I could circumvent the problem by just not using special characters when naming folders but it is nevertheless a bit anoying and anyway might provide a solution to the OP's problem.

Any input on how to handle/set LOCALE/encodings properly to fix this is highly welcome.

Thanks

Oh, and by the way I'm on a windows 10 machine:

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252   
[3] LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C                   
[5] LC_TIME=Swedish_Sweden.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.6.1  magrittr_1.5    htmltools_0.3.6 tools_3.6.1    
 [5] base64enc_0.1-3 yaml_2.2.0      Rcpp_1.0.1      stringi_1.4.3  
 [9] rmarkdown_1.13  knitr_1.23      jsonlite_1.6    stringr_1.4.0  
[13] digest_0.6.19   xfun_0.7        packrat_0.5.0   evaluate_0.14

Thanks man!!! That is a really coooool discover:)
However it probably won't be the reason my displaying function stop working, since the folder I stow my RMD is named only with English characters.
But I do have to mention that since the day I started using R (probably 2ys before) it was working quite fine, it is only until last month it just suddenly malfunction and won't show the data.frame or head() any objects.
But anyway, thank you a lot for sharing your solution!!!!!

1 Like

Too bad it didn't solve your problem.

A quick follow-up:
The problem might be associated with RStudio projects per se.
If I (in RStudio) run a .rmd- file outside a RStudio-project (Project:(None)) but where the file resides in a special character folder I don't have the problem. However, if I open the same file within a project (and that also resides in the same special character folder) the problem appear!
Moreover, if I open the same file (that still resides in a special character folder) within a project that does not reside in a special character folder I don't have the problem!

Clearly, it is all determined by where the project folder is, not where the particular .rmd file is.
And note that the special character folder name could be anywhere in the path (i.e. if I put my project folder inside a non-special character folder within a special character folder there is still a problem). Hence, if you have your project folder in a User-document-folder named with your name and it contains a special character you would probably have the problem.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.