1

I have R version 3.5.0 and RStudio installed on my work laptop. I downloaded ggplot and plotly from CRAN and installed it using Packages -> install package(s) from local file(s) in R. I then opened RStudio and ran multiple different codes to see if they work. Here is is one I tried running:

df <- data.frame(dose=c("D0.5", "D1", "D2"),
                 len=c(4.2, 10, 29.5))
head(df)
library(ggplot2)
# Basic barplot
p<-ggplot(data=df, aes(x=dose, y=len)) +
  geom_bar(stat="identity")
p

# Horizontal bar plot
p + coord_flip()

But I get the following errors:

> library(ggplot2)
Error: package or namespace load failed for ‘ggplot2’ in rbind(info, getNamespaceInfo(env, "S3methods")):
 number of columns of matrices must match (see arg 2)
In addition: Warning message:
package ‘ggplot2’ was built under R version 4.3.0 
> # Basic barplot
> p<-ggplot(data=df, aes(x=dose, y=len)) +
+   geom_bar(stat="identity")
Error in ggplot(data = df, aes(x = dose, y = len)) : 
  could not find function "ggplot"
> p
Error: object 'p' not found
> 
> # Horizontal bar plot
> p + coord_flip()
Error: object 'p' not found

Does anyone know why I am getting this could be happening?. I was thinking that the R version I have is older than the packages but I read somewhere online that the limitations are minuscule.

Just a note, when I try to install ggplot via R studio by typing the following command install.packages("ggplot2"), I get the following error:

> install.packages("ggplot2")
Installing package into ‘\\lsjsh-mp-ns1/user$/H/R/win-library/3.5’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = "\\lsjsh-mp-ns1/user$/H/R/win-library/3.5"' is not writable
also installing the dependencies ‘lifecycle’, ‘glue’, ‘scales’, ‘withr’


  There are binary versions available but the source versions are later:
          binary source needs_compilation
lifecycle  0.2.0  1.0.1             FALSE
glue       1.4.0  1.6.2              TRUE
scales     1.1.0  1.2.0             FALSE
withr      2.2.0  2.5.0             FALSE
ggplot2    3.3.0  3.3.6             FALSE

  Binaries will be installed
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/glue_1.4.0.zip'
Content type 'application/zip' length 157284 bytes (153 KB)
downloaded 153 KB

package ‘glue’ successfully unpacked and MD5 sums checked
Warning in install.packages :
  cannot remove prior installation of package ‘glue’

The downloaded binary packages are in
    C:\Users\H\AppData\Local\Temp\Rtmp2NJuUu\downloaded_packages
installing the source packages ‘lifecycle’, ‘scales’, ‘withr’, ‘ggplot2’

trying URL 'https://cran.rstudio.com/src/contrib/lifecycle_1.0.1.tar.gz'
Content type 'application/x-gzip' length 99716 bytes (97 KB)
downloaded 97 KB

trying URL 'https://cran.rstudio.com/src/contrib/scales_1.2.0.tar.gz'
Content type 'application/x-gzip' length 270188 bytes (263 KB)
downloaded 263 KB

trying URL 'https://cran.rstudio.com/src/contrib/withr_2.5.0.tar.gz'
Content type 'application/x-gzip' length 102089 bytes (99 KB)
downloaded 99 KB

trying URL 'https://cran.rstudio.com/src/contrib/ggplot2_3.3.6.tar.gz'
Content type 'application/x-gzip' length 3061989 bytes (2.9 MB)
downloaded 2.9 MB

'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-lifecycle'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘lifecycle’ had non-zero exit status
'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-withr'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘withr’ had non-zero exit status
'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-scales'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘scales’ had non-zero exit status
'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-ggplot2'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘ggplot2’ had non-zero exit status

The downloaded source packages are in
    ‘C:\Users\H\AppData\Local\Temp\Rtmp2NJuUu\downloaded_packages’
  • Could you try installing it using ```install.packages("ggplot2", type = "source")```? – Archeologist Jul 04 '22 at 19:56
  • 1
    The binary version of ggplot2 that you installed from CRAN is mated to version 4.3.0. So you would need to find a version of that fits the requirements and capabilities of R 3.5.x or you would need to compile from source. It's somewhat unlikely that the code in the first comment would work unless you have already installed Rtools for R 3.5. The best way forward would be to update R and then reinstall ggplot2 – IRTFM Jul 04 '22 at 20:02
  • @Tourist unfortunately I wouldn't be able to install it in that way as I get errors. IRTFM I believe I will do as you suggested and ask for R to be updated. I was trying to avoid it as it means I need to contact the IT department at work and ask them to install it as it would require admin privileges and could take some time. Is there a way to update it via command prompt or some similar way?. –  Jul 04 '22 at 20:39
  • "unfortunately I wouldn't be able to install it in that way as I get errors" if you would tell us which errors, perhaps we could help with that. – Caspar V. Jul 05 '22 at 02:01
  • I have no updated my question to show the error I get. –  Jul 05 '22 at 09:52
  • It seems your default library location is on a local network server. Always a recipe for headaches, even if it works: network drives are slow(er) and it won't work if you're not connected to the server. In this case, you also seem to miss the authorization to write on the server. Either way, I would create a local directory for your libraries: a folder on your own laptop. The following question explains for Windows how to tell R the location where you want to save libraries: https://stackoverflow.com/questions/15170399/change-r-default-library-path-using-libpaths-in-rprofile-site-fails-to-work – Caspar V. Jul 05 '22 at 23:07

0 Answers0