data.frame 在 RStudio 控制台中显示日期列,预览,但不在块下方
data.frame with Date column ouput in RStudio console,preview, but not below the chunk
使用 Rstudio 3.3.2 的笔记本:
---
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
与 有关。
有谁知道我做错了什么吗?非常感谢。
这确实是 RStudio 当前版本中的一个错误:data.frame
s 包含 Date 对象在笔记本中没有正确呈现。您可以尝试安装最新的每日构建的 RStudio 并确认问题已解决:
我很欣赏 Rigoberta 和 Kevin 的帖子。我遇到了同样的问题 (rstudio 1.0.136)。
我害怕按照 http://dailies.rstudio.com 中的描述使用最新的每日构建:"Daily builds are intended for testing purposes, and are not recommended for general use. For stable builds, please visit rstudio.com."
因为我从未使用过 "unstable" 版本的 rstudio,所以现在似乎是回滚 rstudio 版本的更好方法,但不胜感激。
在等待决定是回到 RStudio 1.0.44 还是前进到 "unstable" 版本时,我发现问题不会发生在矩阵对象上,暂时,我是使用 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)
你可以使用这个功能
bf <- function(x) x %>% ungroup() %>% mutate_if(is.Date, as.character)
使包含日期的数据框按预期显示
```{r}
data.frame(date = as.Date(Sys.time()), num = 1:3) %>% bf
```
日期数
2017-03-18 1
2017-03-18 2
2017-03-18 3
3 行
使用 Rstudio 3.3.2 的笔记本:
---
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
与
有谁知道我做错了什么吗?非常感谢。
这确实是 RStudio 当前版本中的一个错误:data.frame
s 包含 Date 对象在笔记本中没有正确呈现。您可以尝试安装最新的每日构建的 RStudio 并确认问题已解决:
我很欣赏 Rigoberta 和 Kevin 的帖子。我遇到了同样的问题 (rstudio 1.0.136)。
我害怕按照 http://dailies.rstudio.com 中的描述使用最新的每日构建:"Daily builds are intended for testing purposes, and are not recommended for general use. For stable builds, please visit rstudio.com."
因为我从未使用过 "unstable" 版本的 rstudio,所以现在似乎是回滚 rstudio 版本的更好方法,但不胜感激。
在等待决定是回到 RStudio 1.0.44 还是前进到 "unstable" 版本时,我发现问题不会发生在矩阵对象上,暂时,我是使用 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)
你可以使用这个功能
bf <- function(x) x %>% ungroup() %>% mutate_if(is.Date, as.character)
使包含日期的数据框按预期显示
```{r}
data.frame(date = as.Date(Sys.time()), num = 1:3) %>% bf
```
日期数
2017-03-18 1
2017-03-18 2
2017-03-18 3
3 行