有没有办法以data.frames更易读的方式将小字体打印到控制台?
例如,是否可以输出到控制台:
library(MASS)
iris[1:5, ]
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
Run Code Online (Sandbox Code Playgroud)
如
iris[1:5, ]
+--------------+-------------+--------------+-------------+---------+
| Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species |
+--------------+-------------+--------------+-------------+---------+
1 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
2 | 4.9 | 3.0 | 1.4 | 0.2 | …Run Code Online (Sandbox Code Playgroud) 我目前正在将 R Shiny 应用程序部署到 Azure 应用服务,并通过 Active Directory 集成(似乎在幕后使用 Azure easyauth 代理)限制访问。
当我部署rocker/shiny:3.6.0orrocker/shiny:4.0.0容器以简单地查看“hello world”页面时,部署成功。
当我打开 Active Directory 身份验证时,网站挂起,然后返回一个500.
我在此消息的底部附上了错误日志,但我认为它没有关于我可以控制的事情的任何有用信息。
进一步调查表明,如果我部署rocker:shiny:3.5.2或低于,一切都按预期工作。如果我部署rocker/shiny:3.6.0或更高版本,我会得到一个500并且网站挂起。
rocker/shiny:3.5.3在这些问题中报告的症状中部署结果:
所以我很确定根本原因是不同的。
对我来说,这表明rocker/shiny:3.6.0包及以上的变化正在阻止身份验证工作,但恐怕这是我的调试能力停止的地方!
我的问题是 - 我真的只是做错了什么,这是一个已知问题,我如何报告它(以及向谁报告?!)。
谢谢你的帮助,
阿基尔
fail: Middleware[0]
Unhandled exception in request pipeline: System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.IO.IOException: The response ended prematurely.
at System.Net.Http.HttpConnection.FillAsync()
at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed) …Run Code Online (Sandbox Code Playgroud) r shiny shiny-server azure-active-directory azure-web-app-service
我可以按所有列进行分组,除了一个使用data.table吗?我有很多专栏,所以我宁愿避免写出所有专栏colnames.
原因是我想在表格中折叠重复项,我知道一列没有相关性.
library(data.table)
DT <- structure(list(N = c(1, 2, 2), val = c(50, 60, 60), collapse = c("A",
"B", "C")), .Names = c("N", "val", "collapse"), row.names = c(NA,
-3L), class = c("data.table", "data.frame"))
> DT
N val collapse
1: 1 50 A
2: 2 60 B
3: 2 60 C
Run Code Online (Sandbox Code Playgroud)
也就是说,给出DT了类似的东西DT[, print(.SD), by = !collapse]给出了:
> DT[, print(.SD), .(N, val)]
collapse
1: A
collapse
1: B
2: C
Run Code Online (Sandbox Code Playgroud)
没有实际指定.(N, val)?我意识到我可以通过复制和粘贴列名来做到这一点,但我认为也可能有一些优雅的方法来做到这一点.
我想定义一个辅助函数来帮助我更清楚地编写一些布尔过滤器。
\niris这是使用数据集结果的工作示例
library(tidyverse)\n\n\nsepal_config = function(length, width, species, .data) {\n .data$Sepal.Length > length & .data$Sepal.Width < width & .data$Species == species\n}\n\niris %>% \n filter(\n sepal_config(length = 4, width = 3, species = "versicolor", .data = .data) | # 34 rows\n sepal_config(length = 3, width = 3, species = "virginica", .data = .data) # 21 rows\n ) # 55 rows\nRun Code Online (Sandbox Code Playgroud)\n我想在不必传入 的情况下执行此操作.data,并且理想情况下还可以在数据帧范围内评估列名称(即避免此错误)
sepal_config = function(length, width, species) {\n Sepal.Length > length & Sepal.Width < width …Run Code Online (Sandbox Code Playgroud) 有没有更好的方法来实现这一目标?我想从这个向量中删除所有字符串,这些字符串是其他元素的子字符串.
words = c("please can you",
"please can",
"can you",
"how did you",
"did you",
"have you")
> words
[1] "please can you" "please can" "can you" "how did you" "did you" "have you"
library(data.table)
library(stringr)
dt = setDT(expand.grid(word1 = words, word2 = words, stringsAsFactors = FALSE))
dt[, found := str_detect(word1, word2)]
setdiff(words, dt[found == TRUE & word1 != word2, word2])
[1] "please can you" "how did you" "have you"
Run Code Online (Sandbox Code Playgroud)
这有效,但看起来有点矫枉过正,我有兴趣知道一种更优雅的方式.
我试图将仪表板的一些代码分解为模块.我在使用此rCharts代码时遇到问题.我可以将它作为一个应用程序运行,但理想情况下我想将它分成UI和server函数,以便我可以将它们保存在一个包中.
下面的代码显示了应用程序中的工作代码以及作为模块的损坏代码.任何人都可以指出我做错了吗?
谢谢
---
title: "Example"
output:
flexdashboard::flex_dashboard:
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(rCharts)
X <- data.frame(Var1 = rep(1:10, 3),
Var2 = rep(c("control", "treatment1", "treatment2"), each = 10),
Freq = abs(rnorm(30, 0, 1))
)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Broken Code as Module
```{r}
ui2 = function(id) {
ns = NS(id)
mainPanel(plotOutput("plot1", height = "100%"),
showOutput(ns("histogram"), "nvd3"))
}
server2 = function(input, output, session) {
output$histogram <- renderChart2({
n2 <- nPlot(Freq ~ …Run Code Online (Sandbox Code Playgroud) 我的文件夹结构是这样设置的:
- project/
- notebooks/
- notebook1.ipynb
- src/
- module1.py
- __init__.py
- data/
- data.csv
Run Code Online (Sandbox Code Playgroud)
这样我就可以将我的源代码与实际分析分开。我希望能够从中导入模块src并在其中使用它们notebook1,但是每当我打开时notebook1,Jupyter 决定将我的工作目录更改为 inside notebooks。
这使我的导入更难维护,因为我必须相对于 Jupyter 的心血来潮导入东西 - 有什么方法可以修复cwd它project,无论我打开什么文件?
我浏览了文档和我的~/.jupyter/jupyter_notebook_config.py, 文件,但没有发现任何可以帮助我的东西。
编辑:我不想在每个脚本的顶部使用os.chdir或cd。
谢谢你的帮助
我有一个列表结构,它代表这样递给我的表
> l = list(list(1, 4), list(2, 5), list(3, 6))
> str(l)
List of 3
$ :List of 2
..$ : num 1
..$ : num 4
$ :List of 2
..$ : num 2
..$ : num 5
$ :List of 2
..$ : num 3
..$ : num 6
Run Code Online (Sandbox Code Playgroud)
我想将其转换为
> lt = list(x = c(1, 2, 3), y = c(4, 5, 6))
> str(lt)
List of 2
$ x: num [1:3] 1 2 3
$ y: num …Run Code Online (Sandbox Code Playgroud) 如何使用自动正确添加import(data.table)到NAMESPACE文件devtools?
一般来说,如果我的包使用data.table我只是手动编写,但是我不能正确地使用@export和devtools::document创建NAMESPACE文件,因为它要么覆盖我做的添加,要么根本不更新文件.
此外,它说不要手动编辑它...
谢谢
示例package/R/function.R代码
#' @export
#' @import data.table
test_data_table = function(dt) {
dt[, a := 3]
}
Run Code Online (Sandbox Code Playgroud)
调用示例
> test_data_table
function(dt) {
dt[, a := 3]
}
<environment: namespace:package>
> test_data_table(dt)
Show Traceback
Rerun with Debug
Error in `[.data.frame`(x, i, j) : could not find function ":="
Run Code Online (Sandbox Code Playgroud)