2017-02-26 70 views
3

使用Rstudio 3.3.2的笔记本下面:data.frame在RStudio控制台日期列输出中,预览,而不是块

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

当试图用日期列显示data.frame,该data.frame显示在浏览器选项卡,但不低于块本身:

```{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诊断:

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 

涉及this question

有谁知道我做错了什么?提前致谢。

回答

1

这实际上是RStudio当前版本中的错误:data.frame包含Date对象在笔记本中未正确呈现。你可以尝试安装RStudio的最新的每日构建和确认问题得到解决有:

http://dailies.rstudio.com

+0

确实,使用1.1.89解决了这个问题。非常感谢 ! –

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 

为了模拟头部()的行为:

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

您可以使用此功能

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

使包含日期显示dataframes如预期

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

日期NUM

2017年3月18日1
2017年3月18日2
2017年3月18日3
3行