小编Tom*_*eif的帖子

无法找到从未知到文本的转换函数

在我的一个select语句中,我遇到以下错误:

ERROR:  failed to find conversion function from unknown to text
********** Error **********
ERROR: failed to find conversion function from unknown to text
SQL state: XX000
Run Code Online (Sandbox Code Playgroud)

这很容易修复使用cast,但我不完全理解为什么会发生.我将用两个简单的陈述说明我的困惑.

这个没关系:

select 'text'
union all
select 'text';
Run Code Online (Sandbox Code Playgroud)

这将返回错误:

with t as (select 'text')    
select * from t
union all
select 'text'
Run Code Online (Sandbox Code Playgroud)

我知道我可以轻松解决它:

with t as (select 'text'::text)    
select * from t
union all
select 'text'
Run Code Online (Sandbox Code Playgroud)

为什么第二个例子中的转换失败?是否有一些我不理解的逻辑或者这将在PostgreSQL的未来版本中修复?

PostgreSQL 9.1.9

PostgreSQL 9.2.4(SQL小提琴)上的相同行为

postgresql postgresql-9.1 postgresql-9.2

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

如何使用pgAdmin 3将CSV中的数据导入Postgres表?

我需要使用哪个插件或库吗?我想首先在我的本地系统上尝试这个,然后在Heroku Postgresql上做同样的事情

postgresql pgadmin

51
推荐指数
3
解决办法
15万
查看次数

如何在R中获得帮助?

R包有哪些可用的文档?例如,我尝试了解sp包.

除此之外help(sp),搜索帮助和文档的其他功能是什么?

r r-faq

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

如何正确使用testthat expect_error()?

什么是正确使用expect_error()testthat包?我试图从帮助中调整示例,但是当我在错误消息中使用括号时,这会失败.

library(testthat)

# Works
tmp1 <- function() stop("Input is not correct")
    expect_error(tmp1(),"Input is not correct")

# Does not work
tmp2 <- function() stop("Input (x) is not correct")
    expect_error(tmp2(),"Input (x) is not correct")

# Does not work
tmp3 <- function() stop("Input(")
    expect_error(tmp3(),"Input(")
Run Code Online (Sandbox Code Playgroud)

这导致:

> library(testthat)
> 
> # Works
> tmp1 <- function() stop("Input is not correct")
> expect_error(tmp1(),"Input is not correct")
> # Does not work
> tmp2 <- function() stop("Input (x) is not correct")
> …
Run Code Online (Sandbox Code Playgroud)

r testthat

18
推荐指数
2
解决办法
4758
查看次数

检查数据框是否存在

在数据帧名称为字符串的情况下,检查数据帧是否存在的首选方法是什么?我能想到:

df_name <- 'iris'

# Option 1
tryCatch(is.data.frame(get(df_name)), error=function(cond) FALSE)

# Option 2
if (exists(df_name)) is.data.frame(get(df_name)) else FALSE
Run Code Online (Sandbox Code Playgroud)

r dataframe

18
推荐指数
1
解决办法
3万
查看次数

在数据框中按组折叠文本

如何在列中按组聚合数据group并在列中折叠文本text

样本数据:

df <- read.table(header=T, text="
group text
a a1
a a2
a a3
b b1
b b2
c c1
c c2
c c3
")
Run Code Online (Sandbox Code Playgroud)

所需输出(数据框):

group text
a     a1a2a3
b     b1b2
c     c1c2c3
Run Code Online (Sandbox Code Playgroud)

我现在有:

sapply(unique(df$group), function(x) {
  paste0(df[df$group==x,"text"], collapse='')
})
Run Code Online (Sandbox Code Playgroud)

这在某种程度上起作用,因为它返回按组正确折叠的文本,但作为向量:

[1] "a1a2a3" "b1b2"   "c1c2c3"
Run Code Online (Sandbox Code Playgroud)

我需要一个带有group列的数据框.

r

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

Rd文件具有不同的编码

如何正确指定rd文件的编码?我正在尝试将以下帮助文件添加到我的包中:

\name{dummy}
\encoding{ISO-8859-2}
\alias{dummy}
\title{P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.}
\usage{
  dummy(x)
}
\arguments{
  \item{x}{P?íšern? žlu?ou?ký k?? úp?l ?ábelské
  ódy.P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.}
}
\description{
  P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.P?íšern?
  žlu?ou?ký k?? úp?l ?ábelské ódy.
}
\examples{
dummy(x="P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.")
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试安装我的包(使用installfrom devtools)时,我得到:

Warning messages:
1: In fetch(key) : internal error -3 in R_decompress1
2: In strsplit(msg, "\n") : input string 1 is invalid in this …
Run Code Online (Sandbox Code Playgroud)

unicode encoding r devtools character-encoding

14
推荐指数
1
解决办法
4039
查看次数

列出PostgreSQL中具有不同所有者的所有表的约束

我必须是信息模式中访问约束相关数据的关系的所有者吗?我测试了以下内容,似乎我必须是主人.

create schema rights_test;

create table rights_test.t1 (id int primary key);
create table rights_test.t2 (id int references rights_test.t1(id));

select  
        tc.constraint_name, 
        tc.constraint_schema || '.' || tc.table_name || '.' || kcu.column_name as physical_full_name,  
        tc.constraint_schema,
        tc.table_name, 
        kcu.column_name, 
        ccu.table_name as foreign_table_name, 
        ccu.column_name as foreign_column_name,
        tc.constraint_type
    from 
        information_schema.table_constraints as tc  
        join information_schema.key_column_usage as kcu on (tc.constraint_name = kcu.constraint_name and tc.table_name = kcu.table_name)
        join information_schema.constraint_column_usage as ccu on ccu.constraint_name = tc.constraint_name
    where 
        constraint_type in ('PRIMARY KEY','FOREIGN KEY')
        and tc.constraint_schema = 'rights_test'

/*
This will produce desired …
Run Code Online (Sandbox Code Playgroud)

postgresql postgresql-9.1

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

在github上开始新的R包开发

如何使用RStudio中的devtools在github上创建新的存储库?我试过:

  1. 在名为"MyNewRPackage"的github上创建空存储库
  2. 使用ssh连接到我的git存储库,在RStudio中启动了新项目
  3. 已安装和加载的devtools

然后我想我会create("MyNewRPackage")用来初始化目录结构和README.md文件.但是包骨架被创建为我项目的子文件夹而且我有~/MyNewRPackage/MyNewRPackage/R.但我需要在我的github存储库的根文件夹中创建包骨架.

使用devtools和RStudio在github上开始新R包开发的标准方法是什么?

r github devtools rstudio

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

为什么要在PostgreSQL中创建空(无行,无列)表

在回答这个问题时,我了解到你可以在PostgreSQL中创建空表.

create table t();
Run Code Online (Sandbox Code Playgroud)

这有什么实际用例吗?你为什么要创建空表?因为你不知道它会有哪些列?

postgresql

13
推荐指数
3
解决办法
2566
查看次数