R Shiny中的Bytea数据格式 [英] Bytea data format in R shiny

查看:109
本文介绍了R Shiny中的Bytea数据格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我需要从PostgreSQL数据库提取的数据的示例表。
样本数据

This is a sample table for the data I need to extract from a PostgreSQL database. Sample data

如您所见,iv_file(它是一个十六进制数字)列为Bytea格式。因此,当我尝试提取R中的iv_file列时,得到以下内容。

As you can see, the iv_file (it's a hexadecimal number) column in is in Bytea format. So when I try to extract onlu the iv_file column in R, I get the following.

`iv_file
1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 \\x
2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 \\x
3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 \\x
4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 \\x
5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 \\x
6 \\x364630353037303036463035303830303646303530443030364530353142303036453035333730303643303535463030364230353838303036393035414530303638303544313030363630354634303036353035313630313634303533373031363330353537303136323035373730313630303539373031354630354236303135453035443630313544303546363031354330353136303235423035333430323539303535343032353930353733303235373035393130323536303542313032353530354430303235343035463030323533303530453033353230353245303335303035344430333446303536423033344530353842303334443035414130333443303543383033344130354538303334413035303830343438303532373034343730353435303434363035363530343434303538343034343430354132303434333035433230343431303545313034343030353031303533463035314630 

在数据是不一样的原始数据。 (请注意,原始数据也有很长的数字)
那么如何在R中使用bytea数据格式?或如何转换?

The data is not the same as the original data. (Please note that the original data has a long number too) So How do I use bytea data format in R? or how do I convert it?

推荐答案

我不相信您可以转换它。 Bytea数据基本上是叮咬数据。我建议不要将其拉入rdata框架。 Bytea通常是位数据,它是图像或不能以传统格式存储的东西。

I dont believe you can convert it. Bytea data is basically bite data. I would suggest just not pulling it into the rdata frame. Bytea is normally bitdata that is an image or something that can not be stored in a traditional format.

另一种方法是使用JDBC,通常用于处理JDBC。转变。我会看一下require(RPostgreSQL)来了解如何完成它。

Another approach would be to use a JDBC, that normally takes care of the transformations. I would take a look at require(RPostgreSQL) to get a sense of how it can be done.

一旦将其加载到R中,您也许可以将其转换回来尝试这样的事情

You might be able to convert it back once it is loaded into R. Try something like this

udecode <- function(string){
  uconv <- function(chars) intToUtf8(strtoi(chars, 16L))
  ufilter <- function(string) {
  if (substr(string, 1, 1)=="|") uconv(substr(string, 2, 5)) else string
 }
 string <- gsub("\\\\u([[:xdigit:]]{4})", ",|\\1,", string, perl=TRUE)
 strings <- unlist(strsplit(string, ","))
 string <- paste(sapply(strings, ufilter), collapse='')
 return(string)
}

这篇关于R Shiny中的Bytea数据格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆