[Rd] Question about selective importing of package functions...

2013-10-20 Thread Jonathan Greenberg
I'm working on an update for my CRAN package spatial.tools and I noticed
a new warning when running R CMD CHECK --as-cran:

* checking CRAN incoming feasibility ... NOTE
Maintainer: 'Jonathan Asher Greenberg spatial-to...@estarcion.net'
Depends: includes the non-default packages:
  'sp' 'raster' 'rgdal' 'mmap' 'abind' 'parallel' 'foreach'
  'doParallel' 'rgeos'
Adding so many packages to the search path is excessive
and importing selectively is preferable.

Is this a warning that would need to be fixed pre-CRAN (not really sure
how, since I need functions from all of those packages)?  Is there a way to
import only a single function from a package, if that function is a
dependency?

--j

-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

[[alternative HTML version deleted]]

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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Duncan Murdoch

On 13-10-20 4:43 PM, Jonathan Greenberg wrote:

I'm working on an update for my CRAN package spatial.tools and I noticed
a new warning when running R CMD CHECK --as-cran:

* checking CRAN incoming feasibility ... NOTE
Maintainer: 'Jonathan Asher Greenberg spatial-to...@estarcion.net'
Depends: includes the non-default packages:
   'sp' 'raster' 'rgdal' 'mmap' 'abind' 'parallel' 'foreach'
   'doParallel' 'rgeos'
Adding so many packages to the search path is excessive
and importing selectively is preferable.

Is this a warning that would need to be fixed pre-CRAN (not really sure
how, since I need functions from all of those packages)?  Is there a way to
import only a single function from a package, if that function is a
dependency?


You really want to use imports.  Those are defined in the NAMESPACE 
file; you can import everything from a package if you want, but the best 
style is in fact to just import exactly what you need.  This is more 
robust than using Depends, and it doesn't add so much to the user's 
search path, so it's less likely to break something else (e.g. by 
putting a package on the path that masks some function the user already 
had there.)


Duncan Murdoch

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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Jonathan Greenberg
Duncan:

Thanks -- learning something new today -- quick follow-up, will using the
import statements in the NAMESPACE, when a user goes to install.packages(),
auto-install the dependent packages the same way Depends forces?

--j


On Sun, Oct 20, 2013 at 3:49 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 13-10-20 4:43 PM, Jonathan Greenberg wrote:

 I'm working on an update for my CRAN package spatial.tools and I noticed
 a new warning when running R CMD CHECK --as-cran:

 * checking CRAN incoming feasibility ... NOTE
 Maintainer: 'Jonathan Asher Greenberg spatial-to...@estarcion.net'
 Depends: includes the non-default packages:
'sp' 'raster' 'rgdal' 'mmap' 'abind' 'parallel' 'foreach'
'doParallel' 'rgeos'
 Adding so many packages to the search path is excessive
 and importing selectively is preferable.

 Is this a warning that would need to be fixed pre-CRAN (not really sure
 how, since I need functions from all of those packages)?  Is there a way
 to
 import only a single function from a package, if that function is a
 dependency?


 You really want to use imports.  Those are defined in the NAMESPACE file;
 you can import everything from a package if you want, but the best style is
 in fact to just import exactly what you need.  This is more robust than
 using Depends, and it doesn't add so much to the user's search path, so
 it's less likely to break something else (e.g. by putting a package on the
 path that masks some function the user already had there.)

 Duncan Murdoch




-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

[[alternative HTML version deleted]]

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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Gabor Grothendieck
On Sun, Oct 20, 2013 at 4:49 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 13-10-20 4:43 PM, Jonathan Greenberg wrote:

 I'm working on an update for my CRAN package spatial.tools and I noticed
 a new warning when running R CMD CHECK --as-cran:

 * checking CRAN incoming feasibility ... NOTE
 Maintainer: 'Jonathan Asher Greenberg spatial-to...@estarcion.net'
 Depends: includes the non-default packages:
'sp' 'raster' 'rgdal' 'mmap' 'abind' 'parallel' 'foreach'
'doParallel' 'rgeos'
 Adding so many packages to the search path is excessive
 and importing selectively is preferable.

 Is this a warning that would need to be fixed pre-CRAN (not really sure
 how, since I need functions from all of those packages)?  Is there a way
 to
 import only a single function from a package, if that function is a
 dependency?


 You really want to use imports.  Those are defined in the NAMESPACE file;
 you can import everything from a package if you want, but the best style is
 in fact to just import exactly what you need.  This is more robust than
 using Depends, and it doesn't add so much to the user's search path, so it's
 less likely to break something else (e.g. by putting a package on the path
 that masks some function the user already had there.)

That may answer the specific case of the poster but how does one
handle the case
where one wants the user to be able to access the functions in the
dependent package.

For example, sqldf depends on gsubfn which provides fn which is used
with sqldf to
perform substitutions in the SQL string.

library(sqldf)
tt - 3
fn$sqldf(select * from BOD where Time  $tt)

I don't want to ask the user to tediously issue a library(gsubfn) too since
fn is frequently needed and for literally years this has not been necessary.
Also I don't want to duplicate fn's code in sqldf since that makes the whole
thing less modular -- it would imply having to change fn in two places
if anything
in fn changed.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Jonathan Greenberg
One more follow-up -- will I now need to include a library() statement in
each function?

--j


On Sun, Oct 20, 2013 at 3:58 PM, Gabor Grothendieck ggrothendi...@gmail.com
 wrote:

 On Sun, Oct 20, 2013 at 4:49 PM, Duncan Murdoch
 murdoch.dun...@gmail.com wrote:
  On 13-10-20 4:43 PM, Jonathan Greenberg wrote:
 
  I'm working on an update for my CRAN package spatial.tools and I
 noticed
  a new warning when running R CMD CHECK --as-cran:
 
  * checking CRAN incoming feasibility ... NOTE
  Maintainer: 'Jonathan Asher Greenberg spatial-to...@estarcion.net'
  Depends: includes the non-default packages:
 'sp' 'raster' 'rgdal' 'mmap' 'abind' 'parallel' 'foreach'
 'doParallel' 'rgeos'
  Adding so many packages to the search path is excessive
  and importing selectively is preferable.
 
  Is this a warning that would need to be fixed pre-CRAN (not really sure
  how, since I need functions from all of those packages)?  Is there a way
  to
  import only a single function from a package, if that function is a
  dependency?
 
 
  You really want to use imports.  Those are defined in the NAMESPACE file;
  you can import everything from a package if you want, but the best style
 is
  in fact to just import exactly what you need.  This is more robust than
  using Depends, and it doesn't add so much to the user's search path, so
 it's
  less likely to break something else (e.g. by putting a package on the
 path
  that masks some function the user already had there.)

 That may answer the specific case of the poster but how does one
 handle the case
 where one wants the user to be able to access the functions in the
 dependent package.

 For example, sqldf depends on gsubfn which provides fn which is used
 with sqldf to
 perform substitutions in the SQL string.

 library(sqldf)
 tt - 3
 fn$sqldf(select * from BOD where Time  $tt)

 I don't want to ask the user to tediously issue a library(gsubfn) too since
 fn is frequently needed and for literally years this has not been
 necessary.
 Also I don't want to duplicate fn's code in sqldf since that makes the
 whole
 thing less modular -- it would imply having to change fn in two places
 if anything
 in fn changed.

 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com




-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

[[alternative HTML version deleted]]

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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Dirk Eddelbuettel

On 20 October 2013 at 16:20, Jonathan Greenberg wrote:
| One more follow-up -- will I now need to include a library() statement in
| each function?

No.

NAMESPACE entry, coupled with Imports: in DESCRIPTION.

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Jonathan Greenberg
To be clear, if I used Depends: somepackage before, and switched over to
using Imports: somepackage, I'll need to mod my code that used to have a
call to, say, somefunction to now have somepackage::somefunction, correct?

--j


On Sun, Oct 20, 2013 at 5:34 PM, Dirk Eddelbuettel e...@debian.org wrote:


 On 20 October 2013 at 16:20, Jonathan Greenberg wrote:
 | One more follow-up -- will I now need to include a library() statement in
 | each function?

 No.

 NAMESPACE entry, coupled with Imports: in DESCRIPTION.

 Dirk

 --
 Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com




-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

[[alternative HTML version deleted]]

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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Duncan Murdoch

On 13-10-20 4:54 PM, Jonathan Greenberg wrote:

Duncan:

Thanks -- learning something new today -- quick follow-up, will using
the import statements in the NAMESPACE, when a user goes to
install.packages(), auto-install the dependent packages the same way
Depends forces?



You need to list the other packages in Imports instead of Depends; then 
the answer is yes.


Duncan Murdoch


--j


On Sun, Oct 20, 2013 at 3:49 PM, Duncan Murdoch
murdoch.dun...@gmail.com mailto:murdoch.dun...@gmail.com wrote:

On 13-10-20 4:43 PM, Jonathan Greenberg wrote:

I'm working on an update for my CRAN package spatial.tools and
I noticed
a new warning when running R CMD CHECK --as-cran:

* checking CRAN incoming feasibility ... NOTE
Maintainer: 'Jonathan Asher Greenberg
spatial-to...@estarcion.net mailto:spatial-to...@estarcion.net'
Depends: includes the non-default packages:
'sp' 'raster' 'rgdal' 'mmap' 'abind' 'parallel' 'foreach'
'doParallel' 'rgeos'
Adding so many packages to the search path is excessive
and importing selectively is preferable.

Is this a warning that would need to be fixed pre-CRAN (not
really sure
how, since I need functions from all of those packages)?  Is
there a way to
import only a single function from a package, if that function is a
dependency?


You really want to use imports.  Those are defined in the NAMESPACE
file; you can import everything from a package if you want, but the
best style is in fact to just import exactly what you need.  This is
more robust than using Depends, and it doesn't add so much to the
user's search path, so it's less likely to break something else
(e.g. by putting a package on the path that masks some function the
user already had there.)

Duncan Murdoch




--
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/ http://www.geog.illinois.edu/%7Ejgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com mailto:jgrn...@hotmail.com,
Gchat: jgrn307, Skype: jgrn3007


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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Gabriel Becker
Jonathan,

import/importFrom directives within the NAMESPACE places the symbol(s)
within your package's namespace. They are treated exactly the same as
(non-exported) symbols your code defines.

~G


On Sun, Oct 20, 2013 at 3:41 PM, Jonathan Greenberg j...@illinois.eduwrote:

 To be clear, if I used Depends: somepackage before, and switched over to
 using Imports: somepackage, I'll need to mod my code that used to have a
 call to, say, somefunction to now have somepackage::somefunction, correct?

 --j


 On Sun, Oct 20, 2013 at 5:34 PM, Dirk Eddelbuettel e...@debian.org wrote:

 
  On 20 October 2013 at 16:20, Jonathan Greenberg wrote:
  | One more follow-up -- will I now need to include a library() statement
 in
  | each function?
 
  No.
 
  NAMESPACE entry, coupled with Imports: in DESCRIPTION.
 
  Dirk
 
  --
  Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com
 



 --
 Jonathan A. Greenberg, PhD
 Assistant Professor
 Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
 Department of Geography and Geographic Information Science
 University of Illinois at Urbana-Champaign
 259 Computing Applications Building, MC-150
 605 East Springfield Avenue
 Champaign, IL  61820-6371
 Phone: 217-300-1924
 http://www.geog.illinois.edu/~jgrn/
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

 [[alternative HTML version deleted]]

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




-- 
Gabriel Becker
Graduate Student
Statistics Department
University of California, Davis

[[alternative HTML version deleted]]

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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Duncan Murdoch

On 13-10-20 6:41 PM, Jonathan Greenberg wrote:

To be clear, if I used Depends: somepackage before, and switched over to
using Imports: somepackage, I'll need to mod my code that used to have a
call to, say, somefunction to now have somepackage::somefunction, correct?


No.  You need to modify both the DESCRIPTION file as you say above, and 
the NAMESPACE file to say what to import.  Once you do that, those 
functions will appear to your own package functions without any prefix 
needed.


Duncan Murdoch



--j


On Sun, Oct 20, 2013 at 5:34 PM, Dirk Eddelbuettel e...@debian.org wrote:



On 20 October 2013 at 16:20, Jonathan Greenberg wrote:
| One more follow-up -- will I now need to include a library() statement in
| each function?

No.

NAMESPACE entry, coupled with Imports: in DESCRIPTION.

Dirk

--
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com







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


Re: [Rd] Question about selective importing of package functions...

2013-10-20 Thread Paul Gilbert



On 13-10-20 04:58 PM, Gabor Grothendieck wrote:

On Sun, Oct 20, 2013 at 4:49 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:

On 13-10-20 4:43 PM, Jonathan Greenberg wrote:


I'm working on an update for my CRAN package spatial.tools and I noticed
a new warning when running R CMD CHECK --as-cran:

* checking CRAN incoming feasibility ... NOTE
Maintainer: 'Jonathan Asher Greenberg spatial-to...@estarcion.net'
Depends: includes the non-default packages:
'sp' 'raster' 'rgdal' 'mmap' 'abind' 'parallel' 'foreach'
'doParallel' 'rgeos'
Adding so many packages to the search path is excessive
and importing selectively is preferable.

Is this a warning that would need to be fixed pre-CRAN (not really sure
how, since I need functions from all of those packages)?  Is there a way
to
import only a single function from a package, if that function is a
dependency?



You really want to use imports.  Those are defined in the NAMESPACE file;
you can import everything from a package if you want, but the best style is
in fact to just import exactly what you need.  This is more robust than
using Depends, and it doesn't add so much to the user's search path, so it's
less likely to break something else (e.g. by putting a package on the path
that masks some function the user already had there.)


That may answer the specific case of the poster but how does one
handle the case
where one wants the user to be able to access the functions in the
dependent package.


There are two answers to this, depending on how much of the dependent 
package you want to make available to the user. If you want most of that 
package to be available then this is the (only?) exception to the rule. 
From Writing R Extensions:


  Field ‘Depends’ should nowadays be used rarely, only for packages
  which are intended to be put on the search path to make their
  facilities available to the end user (and not to the package itself):
  for example it makes sense that a user of package latticeExtra would
   want the functions of package lattice made available.

If you really only want to make a couple of functions available then you 
can import and export the functions. Currently this has the unfortunate 
side effect that you need to document the functions, you cannot just 
re-direct to the documentation in the imported package, at least, I have 
not figured out how to do that.


Paul



For example, sqldf depends on gsubfn which provides fn which is used
with sqldf to
perform substitutions in the SQL string.

library(sqldf)
tt - 3
fn$sqldf(select * from BOD where Time  $tt)

I don't want to ask the user to tediously issue a library(gsubfn) too since
fn is frequently needed and for literally years this has not been necessary.
Also I don't want to duplicate fn's code in sqldf since that makes the whole
thing less modular -- it would imply having to change fn in two places
if anything
in fn changed.



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