Re: [Rd] Non-webby links on Windows web page

2014-11-12 Thread Jeroen Ooms
This caused by the Berkeley web server setting strange content-types.
It is probably more suitable to report this to the Berkeley mirror
admin or cran maintainers.

> library(httr)
> GET("http://cran.cnr.berkeley.edu/bin/windows/base/README.R-3.1.2";)$headers["content-type"]
$`content-type`
[1] "application/x-troff-man"

> GET("http://cran.r-project.org/bin/windows/base/README.R-3.1.2";)$headers["content-type"]
$`content-type`
[1] "text/plain"




On Wed, Nov 12, 2014 at 7:05 PM, Boylan, Ross  wrote:
> On the Windows download page the second link is "Installation and other 
> instructions" http://cran.cnr.berkeley.edu/bin/windows/base/README.R-3.1.2.  
> Clicking on this gets me a "download or open as" dialogue rather than a page 
> of text.
>
> I think something like this happened a few years ago, and the problem was the 
> MIME type of the link.
>
> It would be nice to fix.
>
> Thanks.
> Ross Boylan
>
> P.S. I was using http://cran.cnr.berkeley.edu/ and FF 33.1 on Win 7.
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Non-webby links on Windows web page

2014-11-12 Thread Boylan, Ross
On the Windows download page the second link is "Installation and other 
instructions" http://cran.cnr.berkeley.edu/bin/windows/base/README.R-3.1.2.  
Clicking on this gets me a "download or open as" dialogue rather than a page of 
text.

I think something like this happened a few years ago, and the problem was the 
MIME type of the link.

It would be nice to fix.

Thanks.
Ross Boylan

P.S. I was using http://cran.cnr.berkeley.edu/ and FF 33.1 on Win 7.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How to maintain memory in R extension

2014-11-12 Thread Henrik Bengtsson
On Wed, Nov 12, 2014 at 10:20 AM, Martin Morgan  wrote:
> On 11/12/2014 05:36 AM, Zheng Da wrote:
>>
>> Hello,
>>
>> I wrote a system to perform data analysis in C++. Now I am integrating
>> it to R. I need to allocate memory for my own C++ data structures,
>> which can't be represented by any R data structures. I create a global
>> hashtable to keep a reference to the C++ data structures. Whenever I
>> allocate one, I register it in the hashtable and return its key to the
>> R code. So later on, the R code can access the C++ data structures
>> with their keys.
>>
>> The problem is how to perform garbage collection on the C++ data
>> structures. Once an R object that contains the key is garbage
>> collected, the R code can no longer access the corresponding C++ data
>> structure, so I need to deallocate it. Is there any way that the C++
>> code can get notification when an R object gets garbage collected? If
>> not, what is the usual way to manage memory in R extensions?
>
>
> register a finalizer that runs when there are no longer references to the R
> object, see ?reg.finalizer or the interface to R and C finalizers in
> Rinternals.h. If you return more than one reference to a key, then of course
> you'll have to manage these in your own C++ code.

A small but important addition: Make sure your registered finalizer
also works, or at least don't core dump R, if your package (or one of
its dependencies) happens be unloaded by the time the garbage
collector runs.  This task seems easy but can be quite tricky, e.g.
should you reload you package temporarily and what are the side
effects from doing that?

/Henrik

>
> Martin Morgan
>
>>
>> Thanks,
>> Da
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>
> --
> Computational Biology / Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N.
> PO Box 19024 Seattle, WA 98109
>
> Location: Arnold Building M1 B861
> Phone: (206) 667-2793
>
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How to maintain memory in R extension

2014-11-12 Thread Zheng Da
Thank you, Gabor and Martin. It helps a lot.

Da

On Wed, Nov 12, 2014 at 1:20 PM, Martin Morgan  wrote:
> On 11/12/2014 05:36 AM, Zheng Da wrote:
>>
>> Hello,
>>
>> I wrote a system to perform data analysis in C++. Now I am integrating
>> it to R. I need to allocate memory for my own C++ data structures,
>> which can't be represented by any R data structures. I create a global
>> hashtable to keep a reference to the C++ data structures. Whenever I
>> allocate one, I register it in the hashtable and return its key to the
>> R code. So later on, the R code can access the C++ data structures
>> with their keys.
>>
>> The problem is how to perform garbage collection on the C++ data
>> structures. Once an R object that contains the key is garbage
>> collected, the R code can no longer access the corresponding C++ data
>> structure, so I need to deallocate it. Is there any way that the C++
>> code can get notification when an R object gets garbage collected? If
>> not, what is the usual way to manage memory in R extensions?
>
>
> register a finalizer that runs when there are no longer references to the R
> object, see ?reg.finalizer or the interface to R and C finalizers in
> Rinternals.h. If you return more than one reference to a key, then of course
> you'll have to manage these in your own C++ code.
>
> Martin Morgan
>
>
>>
>> Thanks,
>> Da
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>
> --
> Computational Biology / Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N.
> PO Box 19024 Seattle, WA 98109
>
> Location: Arnold Building M1 B861
> Phone: (206) 667-2793

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem with build and check

2014-11-12 Thread Joshua Ulrich
On Wed, Nov 12, 2014 at 1:28 PM, Duncan Murdoch
 wrote:
> On 12/11/2014 2:11 PM, Therneau, Terry M., Ph.D. wrote:
>>
>> I am getting failure of build and check, for an Rd file that has a long
>> argument list.
>> Guess diagnosis: a quoted string beyond a certain point in the argument
>> list is fatal.
>
>
> No, the problem is that % is a comment marker in .Rd.  You need to escape
> those in the dateformat default.  Apparently
> prompt() doesn't know this...
>
> Duncan Murdoch
>
prompt.default does add the escapes for the example section, but not
for the usage section.

>>
>> Example:  Use the function below, create an Rd file for it with prompt().
>> Move the .Rd
>> file to the man directory (no need to edit it) and try building
>>
>> dart.control <- function(server=c("production", "integration",
>> "development",
>> "http"),
>>out.poll.duration = 5,
>>out.poll.increase = 1.1,
>>out.poll.max = 30,
>>out.poll.timeout = 3600,
>>netrc.path,
>>netrc.server = "ldap",
>>rtype = c("xml", "json"),
>>dateformat= "%Y-%m-%d") {
>>
>>   server <- match.arg(server)
>>   server
>> }
>>
>> I created a package "dummy" with only this function, and get the following
>> on my Linux box.
>>
>> tmt-local2021% R CMD build dummy
>> * checking for file ‘dummy/DESCRIPTION’ ... OK
>> * preparing ‘dummy’:
>> * checking DESCRIPTION meta-information ... OK
>> Warning: newline within quoted string at dart.control.Rd:11
>> Warning: /tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd:46:
>> unexpected
>> section header '\value'
>> Warning: newline within quoted string at dart.control.Rd:11
>> Error in
>> parse_Rd("/tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd", :
>> Unexpected end of input (in " quoted string opened at
>> dart.control.Rd:88:16)
>> Execution halted
>>
>> Session info for my version
>>   > sessionInfo()
>> R Under development (unstable) (2014-10-30 r66907)
>> Platform: i686-pc-linux-gnu (32-bit)
>>
>> locale:
>>[1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>>[3] LC_TIME=en_US.UTF-8LC_COLLATE=C
>>[5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>>[7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>>[9] LC_ADDRESS=C   LC_TELEPHONE=C
>> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods base
>>
>>
>> Terry T.
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem with build and check

2014-11-12 Thread William Dunlap
'Writing R Extensions', section 2.1 Rd format, says"

Comments run from a percent symbol % to the end of the line in all types of
text (as on the first line of the load example).

Because backslashes, braces and percent symbols have special meaning, to
enter them into text sometimes requires escapes using a backslash. In
general balanced braces do not need to be escaped, but percent symbols
always do. For the complete list of macros and rules for escapes, see “Parsing
Rd files” .




Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Nov 12, 2014 at 11:11 AM, Therneau, Terry M., Ph.D. <
thern...@mayo.edu> wrote:

> I am getting failure of build and check, for an Rd file that has a long
> argument list.
> Guess diagnosis: a quoted string beyond a certain point in the argument
> list is fatal.
>
> Example:  Use the function below, create an Rd file for it with prompt().
> Move the .Rd file to the man directory (no need to edit it) and try building
>
> dart.control <- function(server=c("production", "integration",
> "development",
>   "http"),
>  out.poll.duration = 5,
>  out.poll.increase = 1.1,
>  out.poll.max = 30,
>  out.poll.timeout = 3600,
>  netrc.path,
>  netrc.server = "ldap",
>  rtype = c("xml", "json"),
>  dateformat= "%Y-%m-%d") {
>
> server <- match.arg(server)
> server
> }
>
> I created a package "dummy" with only this function, and get the following
> on my Linux box.
>
> tmt-local2021% R CMD build dummy
> * checking for file ‘dummy/DESCRIPTION’ ... OK
> * preparing ‘dummy’:
> * checking DESCRIPTION meta-information ... OK
> Warning: newline within quoted string at dart.control.Rd:11
> Warning: /tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd:46:
> unexpected section header '\value'
> Warning: newline within quoted string at dart.control.Rd:11
> Error in 
> parse_Rd("/tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd",
> :
>   Unexpected end of input (in " quoted string opened at
> dart.control.Rd:88:16)
> Execution halted
>
> Session info for my version
> > sessionInfo()
> R Under development (unstable) (2014-10-30 r66907)
> Platform: i686-pc-linux-gnu (32-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=C
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods base
>
>
> Terry T.
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem with build and check

2014-11-12 Thread Duncan Murdoch

On 12/11/2014 2:11 PM, Therneau, Terry M., Ph.D. wrote:

I am getting failure of build and check, for an Rd file that has a long 
argument list.
Guess diagnosis: a quoted string beyond a certain point in the argument list is 
fatal.


No, the problem is that % is a comment marker in .Rd.  You need to 
escape those in the dateformat default.  Apparently

prompt() doesn't know this...

Duncan Murdoch


Example:  Use the function below, create an Rd file for it with prompt().  Move 
the .Rd
file to the man directory (no need to edit it) and try building

dart.control <- function(server=c("production", "integration", "development",
"http"),
   out.poll.duration = 5,
   out.poll.increase = 1.1,
   out.poll.max = 30,
   out.poll.timeout = 3600,
   netrc.path,
   netrc.server = "ldap",
   rtype = c("xml", "json"),
   dateformat= "%Y-%m-%d") {

  server <- match.arg(server)
  server
}

I created a package "dummy" with only this function, and get the following on 
my Linux box.

tmt-local2021% R CMD build dummy
* checking for file ‘dummy/DESCRIPTION’ ... OK
* preparing ‘dummy’:
* checking DESCRIPTION meta-information ... OK
Warning: newline within quoted string at dart.control.Rd:11
Warning: /tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd:46: 
unexpected
section header '\value'
Warning: newline within quoted string at dart.control.Rd:11
Error in 
parse_Rd("/tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd", :
Unexpected end of input (in " quoted string opened at dart.control.Rd:88:16)
Execution halted

Session info for my version
  > sessionInfo()
R Under development (unstable) (2014-10-30 r66907)
Platform: i686-pc-linux-gnu (32-bit)

locale:
   [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
   [3] LC_TIME=en_US.UTF-8LC_COLLATE=C
   [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
   [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
   [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods base


Terry T.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem with build and check

2014-11-12 Thread Enrico Schumann
On Wed, 12 Nov 2014, "Therneau, Terry M., Ph.D."  writes:

> I am getting failure of build and check, for an Rd file that has a long 
> argument list.
> Guess diagnosis: a quoted string beyond a certain point in the argument list 
> is fatal.

Another guess: should you not escape the '%'?  That is, write
"\%Y-\%m-\%d"?  [Untested.]

> Example:  Use the function below, create an Rd file for it with
> prompt().  Move the .Rd file to the man directory (no need to edit it)
> and try building
>
> dart.control <- function(server=c("production", "integration", "development",
>   "http"),
>  out.poll.duration = 5,
>  out.poll.increase = 1.1,
>  out.poll.max = 30,
>  out.poll.timeout = 3600,
>  netrc.path,
>  netrc.server = "ldap",
>  rtype = c("xml", "json"),
>  dateformat= "%Y-%m-%d") {
>
> server <- match.arg(server)
> server
> }
>
> I created a package "dummy" with only this function, and get the following on 
> my Linux box.
>
> tmt-local2021% R CMD build dummy
> * checking for file ‘dummy/DESCRIPTION’ ... OK
> * preparing ‘dummy’:
> * checking DESCRIPTION meta-information ... OK
> Warning: newline within quoted string at dart.control.Rd:11
> Warning:
> /tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd:46:
> unexpected section header '\value'
> Warning: newline within quoted string at dart.control.Rd:11
> Error in 
> parse_Rd("/tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd", :
>   Unexpected end of input (in " quoted string opened at dart.control.Rd:88:16)
> Execution halted
>
> Session info for my version
>> sessionInfo()
> R Under development (unstable) (2014-10-30 r66907)
> Platform: i686-pc-linux-gnu (32-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=C
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods base
>
>
> Terry T.
>


-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem with build and check

2014-11-12 Thread Paul Gilbert
I certainly have longer argument lists with no problem. More likely the 
Rd file needs special consideration for %.


Paul

On 11/12/2014 02:11 PM, Therneau, Terry M., Ph.D. wrote:

I am getting failure of build and check, for an Rd file that has a long
argument list.
Guess diagnosis: a quoted string beyond a certain point in the argument
list is fatal.

Example:  Use the function below, create an Rd file for it with
prompt().  Move the .Rd file to the man directory (no need to edit it)
and try building

dart.control <- function(server=c("production", "integration",
"development",
   "http"),
  out.poll.duration = 5,
  out.poll.increase = 1.1,
  out.poll.max = 30,
  out.poll.timeout = 3600,
  netrc.path,
  netrc.server = "ldap",
  rtype = c("xml", "json"),
  dateformat= "%Y-%m-%d") {

 server <- match.arg(server)
 server
}

I created a package "dummy" with only this function, and get the
following on my Linux box.

tmt-local2021% R CMD build dummy
* checking for file ‘dummy/DESCRIPTION’ ... OK
* preparing ‘dummy’:
* checking DESCRIPTION meta-information ... OK
Warning: newline within quoted string at dart.control.Rd:11
Warning:
/tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd:46:
unexpected section header '\value'
Warning: newline within quoted string at dart.control.Rd:11
Error in
parse_Rd("/tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd", :
   Unexpected end of input (in " quoted string opened at
dart.control.Rd:88:16)
Execution halted

Session info for my version
 > sessionInfo()
R Under development (unstable) (2014-10-30 r66907)
Platform: i686-pc-linux-gnu (32-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8LC_COLLATE=C
  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
  [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods base


Terry T.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Problem with build and check

2014-11-12 Thread Therneau, Terry M., Ph.D.

I am getting failure of build and check, for an Rd file that has a long 
argument list.
Guess diagnosis: a quoted string beyond a certain point in the argument list is 
fatal.

Example:  Use the function below, create an Rd file for it with prompt().  Move the .Rd 
file to the man directory (no need to edit it) and try building


dart.control <- function(server=c("production", "integration", "development",
  "http"),
 out.poll.duration = 5,
 out.poll.increase = 1.1,
 out.poll.max = 30,
 out.poll.timeout = 3600,
 netrc.path,
 netrc.server = "ldap",
 rtype = c("xml", "json"),
 dateformat= "%Y-%m-%d") {

server <- match.arg(server)
server
}

I created a package "dummy" with only this function, and get the following on 
my Linux box.

tmt-local2021% R CMD build dummy
* checking for file ‘dummy/DESCRIPTION’ ... OK
* preparing ‘dummy’:
* checking DESCRIPTION meta-information ... OK
Warning: newline within quoted string at dart.control.Rd:11
Warning: /tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd:46: unexpected 
section header '\value'

Warning: newline within quoted string at dart.control.Rd:11
Error in 
parse_Rd("/tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd", :
  Unexpected end of input (in " quoted string opened at dart.control.Rd:88:16)
Execution halted

Session info for my version
> sessionInfo()
R Under development (unstable) (2014-10-30 r66907)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=C
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods base


Terry T.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How to maintain memory in R extension

2014-11-12 Thread Martin Morgan

On 11/12/2014 05:36 AM, Zheng Da wrote:

Hello,

I wrote a system to perform data analysis in C++. Now I am integrating
it to R. I need to allocate memory for my own C++ data structures,
which can't be represented by any R data structures. I create a global
hashtable to keep a reference to the C++ data structures. Whenever I
allocate one, I register it in the hashtable and return its key to the
R code. So later on, the R code can access the C++ data structures
with their keys.

The problem is how to perform garbage collection on the C++ data
structures. Once an R object that contains the key is garbage
collected, the R code can no longer access the corresponding C++ data
structure, so I need to deallocate it. Is there any way that the C++
code can get notification when an R object gets garbage collected? If
not, what is the usual way to manage memory in R extensions?


register a finalizer that runs when there are no longer references to the R 
object, see ?reg.finalizer or the interface to R and C finalizers in 
Rinternals.h. If you return more than one reference to a key, then of course 
you'll have to manage these in your own C++ code.


Martin Morgan



Thanks,
Da

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel




--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How to maintain memory in R extension

2014-11-12 Thread Gábor Csárdi
Hi,

I think you need external pointers:
http://cran.r-project.org/doc/manuals/r-release/R-exts.html#External-pointers-and-weak-references
The docs also has an example.

See more examples from other R packages here:
https://github.com/search?q=R_MakeExternalPtr+user%3Acran&type=Code&utf8=%E2%9C%93

Gabor

On Wed, Nov 12, 2014 at 8:36 AM, Zheng Da  wrote:
> Hello,
>
> I wrote a system to perform data analysis in C++. Now I am integrating
> it to R. I need to allocate memory for my own C++ data structures,
> which can't be represented by any R data structures. I create a global
> hashtable to keep a reference to the C++ data structures. Whenever I
> allocate one, I register it in the hashtable and return its key to the
> R code. So later on, the R code can access the C++ data structures
> with their keys.
>
> The problem is how to perform garbage collection on the C++ data
> structures. Once an R object that contains the key is garbage
> collected, the R code can no longer access the corresponding C++ data
> structure, so I need to deallocate it. Is there any way that the C++
> code can get notification when an R object gets garbage collected? If
> not, what is the usual way to manage memory in R extensions?
>
> Thanks,
> Da
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] How to maintain memory in R extension

2014-11-12 Thread Zheng Da
Hello,

I wrote a system to perform data analysis in C++. Now I am integrating
it to R. I need to allocate memory for my own C++ data structures,
which can't be represented by any R data structures. I create a global
hashtable to keep a reference to the C++ data structures. Whenever I
allocate one, I register it in the hashtable and return its key to the
R code. So later on, the R code can access the C++ data structures
with their keys.

The problem is how to perform garbage collection on the C++ data
structures. Once an R object that contains the key is garbage
collected, the R code can no longer access the corresponding C++ data
structure, so I need to deallocate it. Is there any way that the C++
code can get notification when an R object gets garbage collected? If
not, what is the usual way to manage memory in R extensions?

Thanks,
Da

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel