文件错误(con,“r”):运行Dimple Chart时无法在RStudio中打开连接

时间:2015-03-23 09:46:01

标签: r rstudio rcharts dimple.js

昨天我在RStudio中创建了一个简单的应用程序,如果给定一定年限,将会生成该范围内每年人口的动画图表。我上床睡觉时效果很好。醒来,重新启动机器,运行相同的代码,现在我收到错误

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'C:\Users\Tee\Desktop\Sandbox\dimple/config.yml': No such file or directory

当我放入一个断点并逐步执行我的代码时,我发现错误是在倒数第二行(71)return(d1)上抛出的。我很困惑,因为我没有看到这一行是如何查看与它无关的目录(\dimple目录包含不同的Shiny App)并且正在查找我不知道且从未听说过的文件( config.yml)。整个代码如下:

library(rCharts)
library(plyr)


getData <- function(startyr,endyear) {
  df <- read.csv("C:\\path_to_csv\\data2.csv")
  df <- subset(df,(year >= startyr & year <= endyear))
  return(df)
}


# DimpleJS pyramid

myPyramid <- function(startyear, endyear, colors=NULL) {
  dat <- getData(startyear, endyear)
  dat$n <- ifelse(dat$sex == 'MAL', -1 * dat$n, 1 * dat$n)
  dat$gencode <- ifelse(dat$sex == 'MAL', 1, 2)

  d1 <- dPlot(
    x = "n", 
    y = "agegrp", 
    groups = "sex", 
    data = dat, 
    type = 'bar')


  d1$yAxis(type = "addCategoryAxis", orderRule = "ord")
  d1$xAxis(type = "addMeasureAxis")
  d1$legend( x = 60, y = 10, width = 700, height = 20, horizontalAlign = "right")

  if (!is.null(colors)){
    d1$colorAxis(
      type = "addColorAxis", 
      colorSeries = "gencode", 
      palette = colors
    )
  }
  if (endyear - startyear >= 1) {
    d1$set(storyboard = "year")
    max_x <- round_any(max(dat$n), 1000, f = ceiling)
    min_x <- round_any(min(dat$n), 1000, f = floor)
    d1$xAxis(overrideMax = max_x, overrideMin = min_x)
  }

  if (max(dat$n >= 1000000)) {
    d1$setTemplate( afterScript = 
                      "
                    <script>
                    x._getFormat = function () {
                    return function(d) {
                    return d3.format(',.1f')(Math.abs(d) / 1000000) + 'm';
                    };
                    };
                    myChart.draw()
                    </script>
                    ")
  } else {
    d1$setTemplate( afterScript = 
                      "
                    <script>
                    x._getFormat = function () {
                    return function(d) {
                    return d3.format(',.0f')(Math.abs(d) / 1000) + 'k';
                    };
                    };
                    myChart.draw()
                    </script>
                    ")
  }

  return(d1)
}

使用的数据可以在https://raw.githubusercontent.com/kilimba/data/master/data2.csv找到。我不确定昨天和今天之间会发生什么变化,除了我睡着了,在解决这个问题上有什么帮助非常感激?

干杯, Tumaini

0 个答案:

没有答案