<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi all<br>
<br>
Thanks for the replies. After some testing it seems like I dont need
the unsigned stuff and the functions seems to work fine with just a
regular int variable. The functions I wanted to use were just small
parts of a program and in that program bitmap images were loaded and
image data stored as a unsigned char* (for bitmaps unsigned char are
often used due to the 0-255 property I believe). I thought the
simpliest solution was to stick to the original set up (so
replicating the variables) but it seems that is not necessary which
make things easier. <br>
<br>
However, I got curious how to handle this if I need it.<br>
<br>
First, I still dont get the difference between R raw and unsigned
char (if there is one). E.g. <br>
this:<br>
unsigned char a = 'b';<br>
cout << hex << a << endl;<br>
equals<br>
> charToRaw("b")<br>
[1] 62<br>
So can unsigned char be used within Rcpp with RawVector?<br>
For example, is it possible to go from int/char to raw using Rcpp?
Or is the recommended way to use unsigned char to go outside Rcpp as
Tim suggested?<br>
<br>
Again, thanks for the input,<br>
<br>
Gustaf<br>
<br>
<br>
<div class="moz-cite-prefix">On 2014-10-21 10:27, Tim Keitt wrote:<br>
</div>
<blockquote
cite="mid:CANnL8grLuKr53g4Gj+GyON=yUqSwP_Nqhaucc4cykPNn_LG96Q@mail.gmail.com"
type="cite">
<div dir="ltr"><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Mon, Oct 20, 2014 at 2:17 PM,
Gustaf Granath <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:gustaf.granath@gmail.com" target="_blank">gustaf.granath@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Hi<br>
Im trying to use some C++ functions in R. However, these
functions are build around unsigned char* variables (1D
array). I have for example a large matrix in R that
represents black (e.g. 1-bit image, 0 and 1s). I cant find
a solution to convert a character vector into unsigned
char* within Rcpp. Im new to Rcpp and C++ so I might have
missed something obvious here. Please direct me to
resources on this topic (google did not help much).<br>
<br>
A start:<br>
<br>
SEXP test(SEXP cM){<br>
CharacterVector Vc(cM);<br>
int n = Vr.size();<br>
RawVector x(n); //is this the same as unsigned char* ?<br>
//I tried to fill it with
char*(Mr) but I didnt succeed<br>
}<br>
</blockquote>
<div><br>
</div>
<div>I tend to go through the standard library as its less
of a black box. Try creating a std::string and appending
your chars to that string. Then call obj.c_str() to get
the C-style array of chars. Or push the chars onto a
std::vector and do something like &obj[0] to get a 1-D
array.</div>
<div><br>
</div>
<div>THK</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks,<br>
<br>
Gustaf<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Gustaf Granath (PhD)<br>
Post doc<br>
McMaster University<br>
School of Geography & Earth Sciences<br>
<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a moz-do-not-send="true"
href="mailto:Rcpp-devel@lists.r-forge.r-project.org"
target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a moz-do-not-send="true"
href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel"
target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</font></span></blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr"><a moz-do-not-send="true"
href="http://www.keittlab.org/" target="_blank">http://www.keittlab.org/</a></div>
</div>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Gustaf Granath (PhD)
Post doc
McMaster University
School of Geography & Earth Sciences
</pre>
</body>
</html>