小编Vil*_*mko的帖子

如何为ggplot图编写测试

我有很多生成绘图的函数,通常使用ggplot2.现在,我正在生成情节并测试基础数据.但我想知道是否有合理的方法来测试该图包含我期望的图层/选项或图形元素是否符合预期.

例如:

library(ggplot2)
library(scales) # for percent()
library(testthat)

df <- data.frame(
  Response = LETTERS[1:5],
  Proportion = c(0.1,0.2,0.1,0.2,0.4)
)

#' @export plot_fun
plot_fun <- function(df) {
  p1 <- ggplot(df, aes(Response, Proportion)) +
    geom_bar(stat='identity') + 
    scale_y_continuous(labels = percent)
return(p1)
}

test_that("Plot returns ggplot object",{
  p <- plot_fun(df)
  expect_is(p,"ggplot")
})

test_that("Plot uses correct data", {
  p <- plot_fun(df)
  expect_that(df, equals(p$data))

})
Run Code Online (Sandbox Code Playgroud)

这就是我被困住的地方

test_that("Plot layers match expectations",{
  p <- plot_fun(df)
  expect_that(...,...)
})

test_that("Scale is labelled percent",{
  p <- plot_fun(df)
  expect_that(...,...)
})
Run Code Online (Sandbox Code Playgroud)

也许有更直接的方法?

testing unit-testing r ggplot2 testthat

33
推荐指数
3
解决办法
3075
查看次数

R Markdown - 可变输出名称

使用一个R markdown文件,我想创建不同的输出pdf文档,其中输出文件名应在文档中定义.有没有办法说服markdown以这种方式操纵输出文件名?理想情况下,我想通过r块传递文件名.

markdown r knitr r-markdown

29
推荐指数
3
解决办法
2万
查看次数

使用roxygen2记录数据集

我正在尝试使用roxygen2记录R包中的一些数据集.仅考虑其中一个:

  • 我有 mypkg/data/CpG.human.GRCh37.RDa
  • 其中包含一个名为的对象 CpG.human.GRCh37
  • 和一个名为:的文件mypkg/R/cpg-data.R,其中包含:

    #' @name CpG.human.GRCh37
    #' @title CpG islands - human - genome build: GRCh37/hg19
    #' @description This data set list the genomic locations of human CpG islands,
    #' with coordinates based on the GRCh37 / hg19 genome build.
    #' @docType data
    #' @usage CpG.human.GRCh37
    #' @format a \code{RangedData} instance, 1 row per CpG island.
    #' @source UCSC Table Browser
    #' @author Mark Cowley, 2012-03-05
    #' @export
    NULL
    
    Run Code Online (Sandbox Code Playgroud)

当我进行roxygenize时,会创建它mypkg/man/CpG.human.GRCh37.Rd,包含:

    \docType{data}
    \name{CpG.human.GRCh37}
    \alias{CpG.human.GRCh37} …
Run Code Online (Sandbox Code Playgroud)

packaging r rd roxygen2

19
推荐指数
1
解决办法
4009
查看次数

Scala - 期货和并发

我试图了解来自Java背景的Scala期货:我知道你可以写:

val f = Future {   ...    }
Run Code Online (Sandbox Code Playgroud)

那我有两个问题:

  1. 这个未来如何安排?自动?
  2. 它会使用什么样的调度程序?在Java中,您将使用可能是线程池等的执行程序.

此外,如何实现a scheduledFuture,在特定时间延迟后执行的?谢谢

concurrency scala scheduling future promise

13
推荐指数
1
解决办法
1807
查看次数

如何避免在PHP上显示"#!/ usr/bin/php"?

我希望PHP脚本在命令行和网站上运行(我使用Apache和Nginx)所以我把#!/ usr/bin/php放在我脚本的第一行但是出现在网站上......

php apache shell nginx command-line-interface

11
推荐指数
2
解决办法
2万
查看次数

Jekyll转换器为R Markdown

我正在尝试为R Markdown文件编写一个Jekyll转换器.我创建RMarkdownConverter.rb并将其放在我的_plugins目录中.我已经验证其他插件正在运行,但这个不是.我也没有看到任何错误消息,包括我自己放置的消息.似乎没有使用它.但是,Jekyll正在为我的.Rmd文件生成一个HTML文件,但只是将R chuck作为代码查询处理.任何帮助或想法将不胜感激.

RMarkdownConverter.rb 文件:

module Jekyll
    class RMarkdownConverter < Converter
        safe true
        priority :low

    def setup
      STDERR.puts "Setting up R Markdown..."
      return if @setup
      require 'rinruby'
      @setup = true
    rescue
      STDERR.puts 'do `gem install rinruby`'
      raise FatalException.new("Missing dependency: rinruby")
    end

        def matches(ext)
            ext =~ /Rmd/i
        end

        def output_ext(ext)
           '.html'
        end

        def convert(content)
      setup
      STDERR.puts "Using R Markdown..."
      R.eval "require(knitr)"
      R.eval "render_markdown(strict=TRUE)"
      R.assign "content", content
      STDERR.puts content
      R.eval "out <- knit(text=content)"
      R.eval "print(out)"
        end …
Run Code Online (Sandbox Code Playgroud)

r jekyll knitr r-markdown

11
推荐指数
1
解决办法
1269
查看次数

XTend For-Loop支持和添加范围支持

我似乎无法找到一种在Xtend中表达以下内容的好方法,而不需要使用while循环:

for(int i = 0; i < 3; i++){
    println("row ");
}
println("your boat");
Run Code Online (Sandbox Code Playgroud)

所以,我猜我的问题有两个部分:

  • 有没有更好的方法来做到这一点?我在他们的文件中没有看到任何有希望的东西
  • 该语言的很大一部分功能只是Xtend库扩展(它们很棒!).是否有range()我不了解的Python功能?

我最终滚动自己,得到如下内容:

class LanguageUtil {

def static Iterable<Integer> range(int stop) {
    range(0, stop)
}

def static Iterable<Integer> range(int start, int stop) {
    new RangeIterable(start, stop, 1)
}

def static Iterable<Integer> range(int start, int stop, int step) {
    new RangeIterable(start, stop, step)
}
}

// implements Iterator and Iterable which is bad form.
class RangeIterable implements Iterator<Integer>, Iterable<Integer> {
val …
Run Code Online (Sandbox Code Playgroud)

foreach for-loop xtend

9
推荐指数
3
解决办法
8369
查看次数

如何从C#中读取GeoTIFF文件

我已经获得了一些地区的数字高程地图(地球高度图).我的目标是创造逼真的地形.

地形生成没问题.我已经使用VC#和XNA框架练习了这个.

问题是那些高度图文件是GeoTIFF格式,我不知道如何阅读.我以前也没有阅读任何图像文件的经验,这样我就可以使用互联网上有关读取GeoTIFF文件的小技巧来试验一些东西.到目前为止,我一直没有成功.

  • 我拥有的geoTIFF文件是3601 x 3601文件.
  • 每个文件都有两个版本,一个十进制和数值文件.
  • 每个文件都有Geo-Coords经度和纬度的每秒数据以及高度图,即Lon,Lat,海拔高度

如何阅读这些文件:)

我所拥有的文件来自ASTER G-DEM Version-2 LINK TO OFFICIAL DESCRIPTION根据它们GeoTIFF是非常标准的,因为我dwonloaded的一些GeoTIFF展示台向我展示了正确的数据.

我将使用C#.如果我们谈论这种语言,我将不胜感激.


编辑

好吧,我得到了诽谤,这就是我所做的,

using (Tiff tiff = Tiff.Open(@"Test\N41E071_dem.tif", r"))
{
  int width   = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
  int height  = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
  double dpiX = tiff.GetField(TiffTag.XRESOLUTION)[0].ToDouble();
  double dpiY = tiff.GetField(TiffTag.YRESOLUTION)[0].ToDouble(); 

  byte[] scanline        = new byte[tiff.ScanlineSize()]; 
  ushort[] scanline16Bit = new ushort[tiff.ScanlineSize() / 2];

  for (int i = 0; i < height; i++)
  {
    tiff.ReadScanline(scanline, i); //Loading ith Line                        
    MultiplyScanLineAs16BitSamples(scanline, scanline16Bit, 16,i);
  }
}

private static void …
Run Code Online (Sandbox Code Playgroud)

gis geotiff c#-4.0

5
推荐指数
1
解决办法
2万
查看次数

Apache Flink上的zipWithIndex

我想我的指定的输入的每一行id-这应该是一个数0N - 1,其中N在输入的行数.

粗略地说,我希望能够做到以下几点:

val data = sc.textFile(textFilePath, numPartitions)
val rdd = data.map(line => process(line))
val rddMatrixLike = rdd.zipWithIndex.map { case (v, idx) => someStuffWithIndex(idx, v) }
Run Code Online (Sandbox Code Playgroud)

但是在Apache Flink中.可能吗?

scala apache-flink

5
推荐指数
2
解决办法
377
查看次数

在Java中为Maxent分类器创建训练数据

我正在尝试为maxent分类器创建Java实现。我需要将句子分为n不同的类别。

我看了斯坦福maxent分类器中的ColumnDataClassifier。但是我不明白如何创建训练数据。我需要训练数据的形式,其中训练数据包括用于单词的POS标签,以便用于分类的功能将类似于上一个单词,下一个单词等。

我正在寻找带有POS TAGGING句子和句子类别的训练数据。例如:

我/(POS)名称/(POS)是/(POS)XYZ /(POS)类别

任何帮助将不胜感激。

java classification machine-learning maxent

5
推荐指数
1
解决办法
646
查看次数

R降价输出大小

我想使用交互式闪亮应用程序生成R降价页面。它工作正常,但输出在带有滚动条的很小区域中。我想摆脱滚动条,并显示不带滚动条的全宽和全高2个图形。我该如何实现?

我已经尝试过:

options(width = 800)
Run Code Online (Sandbox Code Playgroud)

当前看起来像这样: 在此处输入图片说明

    ---
title: "Spielercluster"
output: html_document
runtime: shiny
---
```{r,echo=FALSE}
library(ggplot2)
library(shiny)

data<-read.csv2('data.csv',header=T,sep=",") 
rawData<-read.csv2('rawData.csv',header=T,sep=",")
cluster<-read.csv2('cluster.csv',header=T,sep=",")
colors<-c("green","red","black")

ui<-fluidPage(plotOutput("plot1", hover = "plot_hover"),
              plotOutput("plot2", hover = "plot_hover"),
              verbatimTextOutput("info")
)

server <- function(input, output) {

  output$plot1 <- renderPlot({
ggplot(rawData, aes(koerpergewicht, groesse, color =  factor(data$gruppe))) +
          geom_point() + labs(title = paste(nlevels(factor(colors))))+geom_point(size=8)+geom_text(aes(label=position),vjust=-1.5)+scale_color_manual(name = "Gruppe",
  labels = c("1 schwer", "2 leicht","3 Zwischengruppe"),
  values = c(rgb(0.9725490196078431,0.4627450980392157,0.4274509803921569,1),rgb(0,0.7294117647058824,0.2196078431372549,1),rgb(0.3803921568627451,0.6117647058823529,1,1)))+ggtitle("Original")
  })

  output$plot2 <- renderPlot({
ggplot(rawData, aes(koerpergewicht, groesse, color =  factor(cluster$x))) +
          geom_point() + labs(title = paste(nlevels(factor(colors))))+geom_point(size=8)+geom_text(aes(label=position),vjust=-1.5)+scale_color_manual(name = …
Run Code Online (Sandbox Code Playgroud)

r knitr r-markdown shiny

5
推荐指数
1
解决办法
2001
查看次数