[R] Use of library(X) in the code of library X.
Bart Kastermans
kasterma at kasterma.net
Sun Jun 8 10:15:18 CEST 2014
Thanks Max and Duncan for the replies.
To Max in particular I would say that ready code written in possibly non-optimal
style (though I did not read enough of caret to have an opinion on that code
in particular) would be good practice too.
When I was a professor and I got complaints about other professors lecturing
I always answered the same; if you want to be a good mathematician you
better learn to get the best from bad lectures since in conferences most talks
are like that. I can only hope other people would say something similar when
they had students complain to them about my bad lectures.
Best,
Bart
http://kasterma.net/
On 06 Jun 2014, at 21:14, Max Kuhn <mxkuhn at gmail.com> wrote:
> That is legacy code but there was a good reason back then.
>
> caret is written to use parallel processing via the foreach package.
> There were some cases where the worker processes did not load the
> required packages (even when I used foreach's ".packages" argument) so
> I would do it explicitly. I don't recall which parallel backend had
> the issue.
>
> The more important lesson is that if you want to "understand some R
> code written by others" you'll learn more bad habits than good ones if
> you examine my packages…
>
> Max
>
> On Fri, Jun 6, 2014 at 2:42 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>> On 06/06/2014 10:26 AM, Bart Kastermans wrote:
>>>
>>> To improve my R skills I try to understand some R code written by others.
>>> Mostly
>>> I am looking at the code of packages I use. Today I looked at the code
>>> for the
>>> caret package
>>>
>>> http://cran.r-project.org/src/contrib/caret_6.0-30.tar.gz
>>>
>>> in particular at the file R/adaptive.R
>>>
>>> This file starts with:
>>>
>>> adaptiveWorkflow <- function(x, y, wts, info, method, ppOpts, ctrl, lev,
>>> metric, maximize, testing = FALSE, ...) {
>>> library(caret)
>>> loadNamespace("caret”)
>>>
>>> From ?library and googling I can’t figure out what this code would do.
>>>
>>> Why would you call library(caret) in the caret package?
>>
>>
>> I don't know that package, and since adaptiveWorkflow is not documented at
>> the user level, I can't tell exactly what the author had in mind. However,
>> code like that could be present for debugging purposes (and is
>> unintentionally present in the CRAN copy), or could be intentional. The
>> library(caret) call has the effect of ensuring that the package is on the
>> search list. (It might have been loaded invisibly by another package.)
>> This is generally considered to be bad form nowadays; packages should
>> function properly without being on the search list.
>>
>> I can't think of a situation where loadNamespace() would do anything --- it
>> would have been called by library().
>>
>> Duncan Murdoch
>>
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list