R-如何使用连接而非文件?

时间:2018-10-18 06:48:51

标签: r file text connection

是否有一种通用的方法来提供一个功能,该功能期望文本文件代替字符串输入?

我想将56000+个svg“文件”转换为栅格/网格格式(位图,png或类似格式)

但是svg文件不是存储为文件,而是存储为数据帧中的字符串

我以为我可以使用textConnection,但是我没有运气:

> pseudo_file <- textConnection(data[1,"svg"])
> bitmap <- rsvg(pseudo_file)
Error: is.raw(svg) is not TRUE

1 个答案:

答案 0 :(得分:1)

以下内容适用于我。确保将字符串识别为R的正确URL:prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/gcc-4.2.2/gcc/../libcpp/include -I/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/gcc-4.2.2/gcc/../libdecnumber -I../libdecnumber /home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/gcc-4.2.2/gcc/cp/g++spec.c) /home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/gcc-4.2.2/gcc/cp/g++spec.c: In function 'lang_specific_driver': /home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/gcc-4.2.2/gcc/cp/g++spec.c:58:7: warning: variable 'saw_verbose_flag' set but not used [-Wunused-but-set-variable] int saw_verbose_flag = 0; ^ /tmp/ccHr34Jc.s: Assembler messages: /tmp/ccHr34Jc.s:120: Error: unrecognized opcode `pushq %r15' /tmp/ccHr34Jc.s:123: Error: unrecognized opcode `pushq %r14' /tmp/ccHr34Jc.s:126: Error: unrecognized opcode `pushq %r13' /tmp/ccHr34Jc.s:129: Error: unrecognized opcode `pushq %r12' /tmp/ccHr34Jc.s:132: Error: unrecognized opcode `pushq %rbp' /tmp/ccHr34Jc.s:135: Error: unrecognized opcode `pushq %rbx' /tmp/ccHr34Jc.s:138: Error: unrecognized opcode `subq $72,%rsp' /tmp/ccHr34Jc.s:141: Error: unrecognized opcode `movl (%rdx),%eax' /tmp/ccHr34Jc.s:143: Error: unrecognized opcode `movq (%rsi),%r15' /tmp/ccHr34Jc.s:145: Error: unrecognized opcode `movq %rdi,32(%rsp)' /tmp/ccHr34Jc.s:147: Error: unrecognized opcode `movslq (%rdi),%rdi' /tmp/ccHr34Jc.s:150: Error: unrecognized opcode `movq %rsi,40(%rsp)' /tmp/ccHr34Jc.s:152: Error: unrecognized opcode `movl $4,%esi' /tmp/ccHr34Jc.s:155: Error: unrecognized opcode `movq %rdx,48(%rsp)' /tmp/ccHr34Jc.s:157: Error: unrecognized opcode `movl %eax,28(%rsp)' /tmp/ccHr34Jc.s:159: Error: unrecognized opcode `movq %rdi,%r12' /tmp/ccHr34Jc.s:162: Error: unrecognized opcode `call xcalloc' /tmp/ccHr34Jc.s:165: Error: unrecognized opcode `cmpl $1,%r12d' /tmp/ccHr34Jc.s:167: Error: unrecognized opcode `movq %rax,(%rsp)' /tmp/ccHr34Jc.s:170: Error: unrecognized opcode `jle .L2' /tmp/ccHr34Jc.s:171: Error: unrecognized opcode `movl $1,24(%rsp)' /tmp/ccHr34Jc.s:172: Error: unrecognized opcode `xorl %r10d,%r10d' /tmp/ccHr34Jc.s:173: Error: unrecognized opcode `xorl %ebp,%ebp' /tmp/ccHr34Jc.s:174: Error: unrecognized opcode `xorl %r11d,%r11d' /tmp/ccHr34Jc.s:175: Error: unrecognized opcode `xorl %r8d,%r8d' /tmp/ccHr34Jc.s:176: Error: unrecognized opcode `movl $1,%ebx' /tmp/ccHr34Jc.s:179: Error: unrecognized opcode `movl $1,%edx' /tmp/ccHr34Jc.s:180: Error: unrecognized opcode `jmp .L19' /tmp/ccHr34Jc.s:187: Error: unrecognized opcode `xorl %ebp,%ebp' /tmp/ccHr34Jc.s:190: Error: unknown .loc sub-directive `discriminator' /tmp/ccHr34Jc.s:190: Error: junk at end of line, first unrecognized character is `2' /tmp/ccHr34Jc.s:191: Error: unrecognized opcode `addl $1,%ebx' /tmp/ccHr34Jc.s:193: Error: unrecognized opcode `cmpl %ebx,%r12d' /tmp/ccHr34Jc.s:194: Error: unrecognized opcode `jle .L173' /tmp/ccHr34Jc.s:198: Error: unrecognized opcode `testq %rbp,%rbp' /tmp/ccHr34Jc.s:199: Error: unrecognized opcode `jne .L42' /tmp/ccHr34Jc.s:202: Error: unrecognized opcode `movslq %ebx,%r14' /tmp/ccHr34Jc.s:203: Error: unrecognized opcode `movq (%r15,%r14,8),%r13' /tmp/ccHr34Jc.s:204: Error: unrecognized opcode `leaq 0(,%r14,8),%r9' /tmp/ccHr34Jc.s:205: Error: unrecognized opcode `movzbl 0(%r13),%ecx' /tmp/ccHr34Jc.s:206: Error: unrecognized opcode `testb %cl,%cl' /tmp/ccHr34Jc.s:207: Error: unrecognized opcode `je .L3' /tmp/ccHr34Jc.s:3060: Error: unknown pseudo-op: `.value' /tmp/ccHr34Jc.s:3068: Error: unknown pseudo-op: `.value' /tmp/ccHr34Jc.s:3072: Error: unknown pseudo-op: `.value' /tmp/ccHr34Jc.s:3079: Error: unknown pseudo-op: `.value' /tmp/ccHr34Jc.s:3086: Error: unknown pseudo-op: `.value' /tmp/ccHr34Jc.s:3092: Error: unknown pseudo-op: `.value' /tmp/ccHr34Jc.s:3096: Error: unknown pseudo-op: `.value' /tmp/ccHr34Jc.s:3097: Error: unknown pseudo-op: `.value' make[5]: *** [g++spec.o] Error 1 /home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/gcc-4.2.2/gcc/cp/Make-lang.in:56: recipe for target 'g++spec.o' failed make[5]: Leaving directory '/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/build-gcc-4.2.2/gcc' make[4]: *** [all-gcc] Error 2 Makefile:4305: recipe for target 'all-gcc' failed make[4]: Leaving directory '/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/build-gcc-4.2.2' make[3]: *** [/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/touch/gcc-4.2.2/bootstrap_gcc] Error 2 Makefile.gcc:111: recipe for target '/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/touch/gcc-4.2.2/bootstrap_gcc' failed make[3]: Leaving directory '/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/tools/gcc-glibc' make[2]: *** [/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/touch/bootstrap_gcc] Error 2 Makefile:118: recipe for target '/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/obj/local-x86_64-unknown-linux-gnu/tools/gcc-glibc/mips-u24kc-linux-gnu-p5-2.6.28.9/touch/bootstrap_gcc' failed make[2]: Leaving directory '/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/tools/gcc-glibc' make[1]: *** [/opt/wios/gcc-4.2.2-uClibc-0.9.30.2-p5/mips-u24kc-linux-gnu/bin/mips-u24kc-linux-gnu-gcc] Error 2 ../mk/makerules-defines:4254: recipe for target '/opt/wios/gcc-4.2.2-uClibc-0.9.30.2-p5/mips-u24kc-linux-gnu/bin/mips-u24kc-linux-gnu-gcc' failed make[1]: Leaving directory '/home/bhashkar/gitblr/prj_code5/rel59_maint/prj_code/src' make: *** [src] Error 2 应替换为\\\

/

如果SVG是字符串,则可以使用library(rsvg) myfiles <- c("example.svg" , "example.svg") for(i in myfiles) { test <- rsvg(i) } test 将SVG字符串转换为原始数据。