2

I'm trying to install rpostgresql on a mac. I want to be able to connect to a server using an IP address and read the data into a dataframe. I downloaded the package from CRAN, and ran the following line:

install.packages('/Users/celenius/Downloads/RPostgreSQL_0.2-1.tar.gz', type='source')

This started to compile the package but resulted with the following error message:

> install.packages('/Users/celenius/Downloads/RPostgreSQL_0.2-1.tar.gz', type='source')
Installing package(s) into ‘/Library/Frameworks/R.framework/Versions/2.14/Resources/library’
(as ‘lib’ is unspecified)
inferring 'repos = NULL' from the file name
* installing *source* package ‘RPostgreSQL’ ...
** package ‘RPostgreSQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for pg_config... /usr/bin/pg_config
checking for "/usr/include/libpq-fe.h"... yes
configure: creating ./config.status
config.status: creating src/Makevars
** libs
*** arch - x86_64
gcc-4.2 -arch x86_64 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -I/usr/include -I/usr/local/include    -fPIC  -g -O2 -c RS-DBI.c -o RS-DBI.o
make: gcc-4.2: No such file or directory
make: *** [RS-DBI.o] Error 1
ERROR: compilation failed for package ‘RPostgreSQL’
* removing ‘/Library/Frameworks/R.framework/Versions/2.14/Resources/library/RPostgreSQL’
Warning in install.packages :
  installation of package ‘/Users/celenius/Downloads/RPostgreSQL_0.2-1.tar.gz’ had non-zero exit status

I've looked through advice on the rpostgresql webpage (1, 2) but a lot of the suggestions are more than a year old so I thought there might be more recent advice on how to install this package.

djq
  • 14,810
  • 45
  • 122
  • 157
  • GCC is no longer included with Xcode 4.2, which is why this is failing. I'm not sure what the workaround in this case would be, it'd probably be best to contact the RPostreSQL developers. – Andrew Marshall Nov 30 '11 at 21:00
  • Are you sure about that? http://hints.macworld.com/article.php?story=20110318050811544 – IRTFM Nov 30 '11 at 21:06
  • @DWin that GCC is no longer included with Xcode? Yes. The article you linked to states that as well. – Andrew Marshall Nov 30 '11 at 21:13

3 Answers3

1

If you want to connect to a postgre db, you also can use RODBC. Just install an ODBC driver (Lion should already include that for postgres) and you are ready to go. I do that for conecting to my local postgre / postgis server and it works just fine.

Dominik
  • 2,753
  • 7
  • 28
  • 32
0

Since postgresql is required to build the package from source, you will need to install it. The easiest way to do so, if you use homebrew, is to simply do the following in a Terminal:

## install postgresql
brew install postgresql

## install the R package
Rscript -e "install.packages('RPostgreSQL', type = 'source')"

## remove postgresql (optional)
brew remove postgresql
amc
  • 263
  • 3
  • 19
0

You need Xcode installed in order to compile. Go into the Mac app store and search for, then install Xcode. It's free.

you can tell whether you already have gcc by doing a quick which gcc-4.2. My guess is that you do not. After installing Xcode, you should get /usr/bin/gcc-4.2 in response.

****EDIT****

After the comments about how you installed Xcode and still don't have gcc-4.2, I did a little bit of reading and it looks like you need to do one of the options listed in this Stack Overflow question: Setting GCC 4.2 as the default compiler on Mac OS X Leopard

This makes me wonder where my gcc-4.2 came from. Probably some fortuitous accident when I first got my MBP.

Community
  • 1
  • 1
JD Long
  • 59,675
  • 58
  • 202
  • 294
  • Ah ok. I had installed XCode from the app store, but not installed gcc which confused me (I remember compiling things previously but not sure which version of gcc it use). I thought I had installed it as `which gcc` returns `/usr/bin/gcc`; but `which gcc-4.2` does not return anything. – djq Nov 30 '11 at 21:30
  • Installed (or reinstalled) Xcode, but `which gcc-4.2` still does not return anything. – djq Nov 30 '11 at 21:34
  • hey wait... the thing I linked to seems to assume you have the gcc-4.2 binaries... which you don't. That seems like a problem. – JD Long Nov 30 '11 at 21:40
  • random thought... after you installed x-code from the app store, did you run the "install xcode" app which it puts in your launcher? I recall doing that and was reminded by it here: http://superuser.com/a/360870 – JD Long Nov 30 '11 at 21:46
  • yes I did. I couldn't remember if I did that the first time, but I just did it now for certain. – djq Nov 30 '11 at 21:49
  • I checked and my gcc-4.2 is located in `/usr/bin/gcc-4.2` and it is signed by Apple, so I presume it came with XCode. – JD Long Nov 30 '11 at 22:01
  • hmm. I'm using Lion which is perhaps why. I think @DWin's link above suggests a solution but it's kind of messy. – djq Nov 30 '11 at 22:05
  • My MBP came with Lion installed. I didn't upgrade from Leopard or any of the other cats. I know, for a fact, I didn't jump through the hoops listed in that link from DWin – JD Long Nov 30 '11 at 22:06