Displaying 20 results from an estimated 83 matches for "chartoraw".
2008 May 21
1
rawToChar(raw(0))
....7.0 patched (2008-04-23 r45466)) that:
> rawToChar(raw(0))
[1] ""
> rawToChar(raw(0), multiple=TRUE)
character(0)
Is this intended or should both return character(0)? Personally, I
would prefer that an empty input vector returns an empty output
vector. Same should then apply to charToRaw(), but right now we get:
> x <- character(0)
> charToRaw(x)
Error in charToRaw(x) : argument must be a character vector of length 1
I am aware of the new rules for R v2.8.0dev on truncating nuls in
character strings. That would make charToRaw(x) return the same
regardless of x==characte...
2018 Feb 17
1
writeLines argument useBytes = TRUE still making conversions
Of course, right after writing this e-mail I tested on my Windows
machine and did not see what I expected:
> charToRaw(before)
[1] c3 a9
> charToRaw(after)
[1] e9
so obviously I'm misunderstanding something as well.
Best,
Kevin
On Sat, Feb 17, 2018 at 2:19 PM, Kevin Ushey <kevinushey at gmail.com> wrote:
> From my understanding, translation is implied in this line of ?file (from the
> Encoding...
2018 Feb 15
2
writeLines argument useBytes = TRUE still making conversions
...e in the system native encoding, and then
> re-encoded as UTF-8 when written to the file. You can see something
> similar with:
>
> > tmp <- '?'
> > tmp <- iconv(tmp, to = 'UTF-8')
> > Encoding(tmp) <- "unknown"
> > charToRaw(iconv(tmp, to = "UTF-8"))
> [1] c3 83 c2 a9
>
> It's worth saying that:
>
> file(..., encoding = "UTF-8")
>
> means "attempt to re-encode strings as UTF-8 when writing to this
> file". However, if you already know your text is UTF-8,...
2012 Jul 20
1
subRaw?
Hello, All:
Do you know of any capability to substitute more then one byte in
an object of class Raw?
Consider the following:
> let4 <- paste(letters[1:4], collapse='')
> (let4Raw <- charToRaw(let4))
[1] 61 62 63 64
> (let. <- sub('bc', '--', let4Raw))
[1] "61" "62" "63" "64"
> # no substitution
> (bc <- charToRaw('bc'))
[1] 62 63
> (ef <- charToRaw('ef'))
[1] 65 66
> (let. <- sub(bc,...
2008 Apr 28
4
R 2.7.0, match() and strings containing \0 - bug?
...ely with R 2.7.0. This seems to be because of a failure
to match() strings after using rawToChar() when the original was
terminated with a "\0" character. Direct equality testing with ==
still works as expected. I can reproduce this as follows:
> x <- "foo"
> y <- c(charToRaw("foo"),as.raw(0))
> z <- rawToChar(y)
> z==x
[1] TRUE
> z=="foo"
[1] TRUE
> z %in% c("foo","bar")
[1] FALSE
> z %in% c("foo","bar","foo\0")
[1] FALSE
But without the nul character it works fine:
> zz <-...
2018 Feb 17
0
writeLines argument useBytes = TRUE still making conversions
....
This is the code I used to convince myself of that case:
conn <- file(tempfile(), encoding = "native.enc", open = "w+")
before <- iconv('?', to = "UTF-8")
cat(before, file = conn, sep = "\n")
after <- readLines(conn)
charToRaw(before)
charToRaw(after)
with output:
> charToRaw(before)
[1] c3 a9
> charToRaw(after)
[1] c3 a9
Best,
Kevin
On Thu, Feb 15, 2018 at 9:16 AM, Ista Zahn <istazahn at gmail.com> wrote:
> On Thu, Feb 15, 2018 at 11:19 AM, Kevin Ushey <kevinushey at gmail.com&...
2011 Aug 22
3
automatic file input
Dear all,
I have 100 files which are used as input.and I have to input the name of my files again and again.the name of the files are 1.out, 2.out......100.out.
I want to know if there is anything like perl so that i can use something like this-
for($f = 1; $f <= 100; $f++) {
$file = $f.".out";
I have tried this thing in R but it does not work.Can somebody please help me.
2009 May 10
2
In C, a fast way to slice a vector?
Hello,
Suppose in the following code,
PROTECT(sr = R_tryEval( .... ))
sr is a RAWSXP vector. I wish to return another RAWSXP starting at
position 13 onwards (base=0).
I could create another RAWSXP of the correct length and then memcpy
the required bytes and length to this new one.
However is there a more efficient method?
Regards
Saptarshi Guha
2007 Aug 31
1
Consistency of serialize(): please enlighten me
...m puzzled with serialize(). It comes down generating identical
hash codes for (apparently) identical objects using digest::digest(),
which in turn relies on serialize(). Here is an example illustration
the issue:
ser <- function(object, ...) {
list(
names = names(object),
namesRaw = charToRaw(names(object)),
ser = serialize(names(object), connection=NULL, ascii=FALSE)
)
} # ser()
# Object to be serialized
key <- key0 <- list(abc="Hello");
# Store results
d <- list();
# 1. As is
d[[1]] <- ser(key);
# 2. Set names and redo (hardwired: identical to what'...
2018 Feb 15
2
writeLines argument useBytes = TRUE still making conversions
I think this behavior is inconsistent with the documentation:
tmp <- '?'
tmp <- iconv(tmp, to = 'UTF-8')
print(Encoding(tmp))
print(charToRaw(tmp))
tmpfilepath <- tempfile()
writeLines(tmp, con = file(tmpfilepath, encoding = 'UTF-8'), useBytes = TRUE)
[1] "UTF-8"
[1] c3 a9
Raw text as hex: c3 83 c2 a9
If I switch to useBytes = FALSE, then the variable is written correctly as c3 a9.
Any thoughts? This behavio...
2023 Apr 13
1
Split String in regex while Keeping Delimiter
...itten a small utility function to approximately extract
"non-standard" characters:
### Identify non-ASCII Characters
# beware: the filtering and the sorting may break the codes;
extract.nonLetters = function(x, rm.space = TRUE, sort=FALSE) {
?? ?code = as.numeric(unique(unlist(lapply(x, charToRaw))));
?? ?isLetter =
?? ???? (code >= 97 & code <= 122) |
?? ???? (code >= 65 & code <= 90);
?? ?code = code[ ! isLetter];
?? ?if(rm.space) {
?? ???? # removes only simple space!
?? ???? code = code[code != 32];
?? ?}
?? ?if(sort) code = sort(code);
?? ?return(code);
}...
2013 May 01
1
Windows, format.POSIXct and character encodings
...1970-01-01 01:00:00 UTC", "1970-02-02 22:00:00 UTC")
ampm <- format(as.POSIXct(times), format = "%p")
x <- gsub(">", "*", paste(ampm, collapse = "+>"))
y <- "??+*??"
identical(x, y)
# [1] TRUE
# But, confusingly, ...
charToRaw(x)
# [1] e5 8d 88 e5 89 8d 2b 2a e5 8d 88 e5 be 8c
charToRaw(y)
# [1] 8c df 91 4f 2b 2a 8c df 8c e3
# So there's at least a small bug with identical
# And this causes a problem when you attempt to do
# stuff with the string
gsub("+", "*", x, fixed = T)
# Error in gsub(&q...
2010 Dec 07
3
More elegant magnitude method
...find the order of number to get a scaling parameter as a
power of 10. I have a function that works *so far*, but it is ugly and
probably buggy. In the interest of avoiding code-based outliers in my
data, I thought I would ask if anyone here has a better way.
> scl <- function(x){
+ length(charToRaw(format(trunc(x), scientific = F)))-1}
> a <- 123456789
> b <- 1E15
> c <- 12.345
> scl(a)
[1] 8
> scl(b)
[1] 15
> scl(c)
[1] 1
Thanks
--------------------------------------
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 2...
2009 Aug 29
2
RFE: vectorize URLdecode
In R 2.9.2,
> URLdecode(c("a%20b", "b%20c"))
[1] "a b"
Warning message:
In charToRaw(URL) : argument should be a character vector of length 1
all but the first element will be ignored
Could URLdecode be modified to actually process all elements of the vector, not
just the first?
Thanks in advance
2012 Jun 08
2
remove leading slash
Hello,
How do I change this:
> cnt_str
[1] "\002" "\001" "\102"
...to this:
> cnt_str
[1] "2" "1" "102"
Having trouble because of this:
> nchar(cnt_str[1])
[1] 1
Thanks!
Ben
[[alternative HTML version deleted]]
2011 Jul 21
2
User input(unknown name and number of files)
...want.My code is like this-
df=read.table("Case2.pileup",fill=T,sep="\t",colClasses="character")
df$V9 <- apply(df, 1, function(x) gsub("\\:|\\$|\\^|!|\\-|1|2|3|4|5|6|7|8|10", "",x[9]))
df$V10 <- sapply(df$V10, function(a)
paste(as.integer(charToRaw(a)), collapse = ' '))
capture.output(print.data.frame(df,row.names=F), file = "end.txt", append = FALSE)
I know it should do it with for loop and an array.I want that if user input 12 files,the dataframe name df should be different for all the 12 files.
Can you please tell me ho...
2017 Sep 14
2
special latin1 do not print as glyphs in current devel on windows
...and that is exactly the problem, IMHO.
Let me show you what I mean. (All output from R 3.5 r73238, see
sessionInfo at the end)
> Sys.getlocale("LC_CTYPE")
[1] "German_Germany.1252"
> x <- c("?", "?", "?", "?")
> sapply(x, charToRaw)
\u0080 \u009e \u009a? ?
80 9e 9a fc
"?", "?", "?" serve as examples in the 80-9F range of CP1252. I also
show the "?" just as an example of a non-ASCII character outside that
range (and because Patrick Perry used it in his bug report which might
be a (sl...
2016 Sep 05
2
How to print UTF-8 encoded strings from a C routine to R's output?
Dear R experts,
It seems that Rprintf has to be used to print from a C routine to guarantee
to write to R?s output according to
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Printing.
However if a string is UTF-8 encoded, non-ASCII characters (e.g., the
infinity symbol http://www.fileformat.info/info/unicode/char/221e/index.htm)
are misprinted.
Is this an unsupported feature or is
2018 Jul 29
2
odd behavior of names
...6101 describes another first-list-name-printed-differently
oddity
with the Windows GUI version of R:
> a <- "One is \u043E\u0434\u0438\u043D\nTwo is \u0434\u0432\u0430\n"
> Encoding(a) # expect "UTF-8"
[1] "UTF-8"
> sapply(strsplit(a, "\n")[[1]], charToRaw)[c(1,1,2)]
$`One is ????`
[1] 4f 6e 65 20 69 73 20 d0 be d0 b4 d0
[13] b8 d0 bd
$`One is <U+043E><U+0434><U+0438><U+043D>`
[1] 4f 6e 65 20 69 73 20 d0 be d0 b4 d0
[13] b8 d0 bd
$`Two is <U+0434><U+0432><U+0430>`
[1] 54 77 6f 20 69 73 20 d0 b4 d0 b2 d0...
2018 Jul 16
2
Output mis-encoded on Windows w/ RGui 3.5.1 in strange case
...quot;apple")
print(output)
If I source this script from RGui on Windows, I see the output:
> source("encoding.R")
list()
[1] "\002??apple\003??"
That is, it's as though R has injected what looks like byte order
marks around the encoded string:
> charToRaw(output)
[1] 02 ff fe 61 70 70 6c 65 03 ff fe
FWIW I see the same output in R-patched and R-devel. Any idea what
might be going on? For what it's worth, I don't see the same issue
with R as run from the terminal.
Thanks,
Kevin