我有一种情况,我需要测试一个变量是否factor(0)只是我尝试分配给它的任何逻辑测试(包括与 NULL 比较)给出logical(0). 如何测试某物是否为空因子?
编辑:请允许我详细说明。
我有一个函数,它查看它接收的向量的属性,但并非每个向量都具有该属性,因此对于没有该属性的向量,当我查询该属性时,attr(vector,"attribute")我的返回值为 factor(0)但是当我将它与 0 进行比较时,我得到logical(0)并将其与 null 或 NA 进行比较也不起作用。有任何想法吗?
我正在尝试确定是否可以shiny DataTable为某些行禁用行选择。
使用I can pre-select rows的selection参数DT::datatable,确定用户是选择行还是列或两者,并完全禁用选择,但我不清楚是否可以指示要排除的特定行。这可能吗?
问候
我有一个带有两个选项卡的闪亮应用程序,每个选项卡都有一个包含 numericInputs 的 DataTable,因此我必须绑定和取消绑定 DataTable 才能使 numericInputs 工作。不幸的是,这造成了反应性问题,我希望有人可以提供帮助。在下面的示例中,如果您更改侧边栏上确定表中数据的输入,则只有打开的选项卡中的表才会实际更新/反应。
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
sidebarPanel(
# choose dataset
selectInput("select","Choose dataset",c("mtcars","iris"))),
# display table
mainPanel(
tabsetPanel(tabPanel("one",DT::dataTableOutput('x1')),
tabPanel("two",DT::dataTableOutput('x2'))),
tags$script(HTML("Shiny.addCustomMessageHandler('unbind-DT', function(id) {
Shiny.unbindAll($('#'+id).find('table').DataTable().table().node());
})")))),
server = function(session, input, output) {
# function for dynamic inputs in DT
shinyInput <- function(FUN,id,num,...) {
inputs <- character(num)
for (i in seq_len(num)) {
inputs[i] <- as.character(FUN(paste0(id,i),label=NULL,...))
}
inputs
}
# function to read DT inputs
shinyValue <- function(id,num) {
unlist(lapply(seq_len(num),function(i) {
value <- input[[paste0(id,i)]]
if (is.null(value)) NA …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 DT 创建一个表,并且我想创建一个显示数据的容器,如下所示。
但是,我最接近的是下面的代码。
library(data.table)
library(DT)
#a custom table container
sketch = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(colspan = 3, 'First'),
th(colspan = 8, 'Criteria')
),
tr(
th(colspan = 3, 'Name1'),
th(colspan = 1, 'Car'),
th(colspan = 3, 'Criteria'),
th(colspan = 2, 'Criteria2'),
th(colspan = 3, 'Criteria3')
),
tr(
lapply(c('vs', 'gear', 'carb', 'Car', 'mpg', 'cyl', 'disp', 'hp', 'drat', 'wt', 'qsec', 'am'), th)
)
)
))
mtcars$Car = row.names(mtcars)
header_trial = mtcars
header_trial = data.table(header_trial)
setkey(header_trial, vs, gear, carb)
setcolorder(header_trial, …Run Code Online (Sandbox Code Playgroud) 我正在使用自定义 R Markdown Latex 模板和 BibTex,但我无法使参考书目正常工作。
使用默认的 pandoc-citeproc 我得到错误:
pandoc-citeproc: Error parsing references: expected [a], encountered Object
Run Code Online (Sandbox Code Playgroud)
这发生在 .tex 文件生成之前,而不是在 .tex 文件编译期间。我试过卸载并重新安装 pandoc,这没有帮助。
当我添加--biblatex为 pandoc 参数时,在生成 .tex 文件后出现一个新错误:
! Undefined control sequence.
l.41 We are writing this using LaTeX \autocite
Run Code Online (Sandbox Code Playgroud)
如果我在 .tex 文件中用 \cite 替换 \autocite ,它会很好地编译。如果我能让 pandoc/biblatex 使用 \cite 而不是 \autocite 那就太好了,这样我就不必手动干预了。我误解了什么吗?
Rcpp我在 PC 上运行 RStudio 时遇到问题。每当我sourceCpp()使用 cpp 文件,甚至是附带的 Hello World 文件时Rcpp::Rcpp.package.skeleton(),我都会收到警告
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]=".../anRpackage/src/../inst/include": The system cannot find the path specified
Run Code Online (Sandbox Code Playgroud)
我搜索了 Stackoverflow,看起来有些人如果他们的包的描述中没有 Depends: Rcpp 就会收到此警告,但我只是在运行,所以sourceCpp()描述文件应该不重要(我还更改了描述文件)。这只是一个警告,所以我编写的类和函数确实出现在 R 中,但在我使用 R 中的函数几次后,RStudio 经常崩溃,这可能相关,也可能不相关。
我的会话信息:
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached …Run Code Online (Sandbox Code Playgroud) 我正在尝试采用这个基本的闪亮应用程序并将其模块化。这有效:
shinyApp(
ui = fluidPage(
DT::dataTableOutput("testTable"),
verbatimTextOutput("two")
),
server = function(input,output) {
output$testTable <- DT::renderDataTable({
mtcars
}, selection=list(mode="multiple",target="row"))
output$two <- renderPrint(input$testTable_rows_selected)
}
)
Run Code Online (Sandbox Code Playgroud)
我想让它成为一个适用于任何 data.frame 的模块
# UI element of module for displaying datatable
testUI <- function(id) {
ns <- NS(id)
DT::dataTableOutput(ns("testTable"))
}
# server element of module that takes a dataframe
# creates all the server elements and returns
# the rows selected
test <- function(input,output,session,data) {
ns <- session$ns
output$testTable <- DT::renderDataTable({
data()
}, selection=list(mode="multiple",target="row"))
return(input[[ns("testTable_rows_selected")]])
}
shinyApp( …Run Code Online (Sandbox Code Playgroud) 我有一个DT内部Rmarkdown,我想在悬停在表数据上时弹出一个图像.
我所拥有的似乎工作,但它扭曲了datatable.
它增加了表行高度以适合图像.我试图减少行大小,css但没有运气.
这是Rmarkdown我到目前为止:
---
title: "Untitled"
author: "dimitris_ps"
date: "3 September 2016"
output: html_document
---
<style type="text/css">
.imgTooltip {
visibility: hidden;
}
.ItemsTooltip:hover .imgTooltip {
visibility: visible;
}
td {
height: 14px;
}
</style>
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(DT)
df <- structure(list(a = c("<a class=\"ItemsTooltip\" href=\"http://www.example.com\" target=\"_blank\"><img class=\"imgTooltip\" src=\"https://i.stack.imgur.com/uSSEu.jpg\"/>my stackoverflow Avatar</a>",
"<a class=\"ItemsTooltip\" href=\"http://www.example.com\" target=\"_blank\"><img class=\"imgTooltip\" src=\"https://i.stack.imgur.com/uSSEu.jpg\"/>my stackoverflow Avatar</a>"
), b = c("<a class=\"ItemsTooltip\" href=\"http://www.example.com\" target=\"_blank\"><img class=\"imgTooltip\" …Run Code Online (Sandbox Code Playgroud) 大多数人可能都熟悉bssplines:
library(splines)
workingModel <- lm(mpg ~ factor(gear) + bs(wt, knots = 5) + hp, data = mtcars)
bs(mtcars$wt, knots = 4)
Run Code Online (Sandbox Code Playgroud)
这使用b样条作为单个变量权重,但您也可以使用多变量样条:
bs(cbind(mtcars$wt,mtcars$hp), knots = 4)
Run Code Online (Sandbox Code Playgroud)
但是这会产生一个行数是行数两倍的矩阵mtcars,所以当我尝试:
brokenModel <- lm(mpg ~ bs(cbind(mtcars$wt,mtcars$hp), knots = 4), data = mtcars)
Run Code Online (Sandbox Code Playgroud)
我得到一个关于不同长度的错误.
我的问题是:如果模型的行数与结果变量不同,我如何在模型中使用多元样条?我是否将结果变量叠加在自身之上y <- c(y, y)?为什么多变量样条曲线会产生额外的行?
谢谢.
我读了这篇关于 Rcpp 中的类和模块的博客文章,我试图重新创建它,但我遇到了麻烦。
这是帖子中代码的缩写版本:
#include <Rcpp.h>
using namespace Rcpp;
class Point {
public:
Point( double x_, double y_) : x(x_), y(y_){}
double x, y ;
} ;
class Shape {
public:
Shape( const Point& center_ ) : center(center_){}
Point center ;
virtual double area() const { return 0.0 ;}
virtual bool contains(const Point& point) const { return false ; }
} ;
RCPP_MODULE(play){
class_<Point>("Point")
.constructor<double,double>()
.field( "x", &Point::x)
.field( "y", &Point::y)
;
class_<Shape>( "Shape" )
.constructor<Point>()
.method( "area", …Run Code Online (Sandbox Code Playgroud) r ×10
dt ×5
shiny ×4
datatables ×2
r-markdown ×2
rcpp ×2
css ×1
latex ×1
lm ×1
markdown ×1
pandoc ×1
regression ×1
rstudio ×1
spline ×1