Data.frame with Date column output in RStudio console, preview, but not lower than fragment

Using a Rstudio 3.3.2 laptop:

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

When trying to display data.frame with the Date column , the data.frame file is displayed on the View tab, but not lower than the fragment itself:

    ```{r}
    df <- data.frame(date=c("31/08/2011", "31/07/2011", "30/06/2011"),values=c(0.8378,0.8457,0.8147))               

    #no Date format ->OK, output below the chunk
    df

    df$dateformatted<-as.Date(strptime(df$date,'%d/%m/%Y'))

    #with Date format -> NOK, no output below the chunk,only in Viewer.
    df 

    ```

RStudio Diagnostics:

26 Feb 2017 20:42:00 [rsession-x] ERROR r error 7 (Unexpected data type); OCCURRED AT: rstudio::core::Error rstudio::r::json::{anonymous}::jsonValueFromVectorElement(SEXP, int, rstudio::core::json::Value*) /home/ubuntu/rstudio/src/cpp/r/RJson.cpp:149; LOGGED FROM: void rstudio::session::modules::rmarkdown::notebook::enqueueChunkOutput(const string&, const string&, const string&, unsigned int, ChunkOutputType, const rstudio::core::FilePath&, const Value&) /home/ubuntu/rstudio/src/cpp/session/modules/rmarkdown/NotebookOutput.cpp:449

refers to this issue .

Does anyone know what I did wrong? Thank you very much in advance.

+3
source share
3 answers

RStudio: data.frame, Date, . RStudio , :

http://dailies.rstudio.com

+1

. (rstudio 1.0.136).

, http://dailies.rstudio.com:" , . , , rstudio.com.

"" rstudio, rstudio, .

, , RStudio 1.0.44 "" , , , print (as.matrix()):

```{r}
df <- data.frame(date = c("31/08/2011", "31/07/2011", "30/06/2011"), values = c(0.8378, 0.8457, 0.8147))
df$dateformatted <- as.Date(strptime(df$date, '%d/%m/%Y'))

print(as.matrix(df), quote = FALSE)
```
     date       values dateformatted
[1,] 31/08/2011 0.8378 2011-08-31   
[2,] 31/07/2011 0.8457 2011-07-31   
[3,] 30/06/2011 0.8147 2011-06-30  

head():

print(as.matrix(df), quote = FALSE, max = length(df) * 6)
+1

You can use this function

bf <- function(x) x %>% ungroup() %>% mutate_if(is.Date, as.character) 

so that data containing dates is displayed as expected

```{r}
data.frame(date = as.Date(Sys.time()), num = 1:3) %>% bf
```

date num

2017-03-18 1
2017-03-18 2
2017-03-18 3
3 lines

0
source

Source: https://habr.com/ru/post/1666540/


All Articles