Rfacebook- could not find function fbOAuth [duplicate] - r

This question already has answers here:
Error: could not find function ... in R
(10 answers)
Closed 8 years ago.
I am having trouble with Rfacebook- I install it, which seems to go fine, but then when I call fbOAuth exactly as I've seen in examples, it says function not found. I wonder if my directories/libraries/working spaces aren't lined up? It's showing a temporary location but I also see an Rfacebook folder get created in my designated library.
Thanks!
package ‘Rfacebook’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Katherine\AppData\Local\Temp\Rtmp23Rk2g\downloaded_packages
> fb_oauth <- fbOAuth(app_id="xxxxx", app_secret = "xxxxx")
Error: could not find function "fbOAuth"

This is R FAQ 7.30; I would have expected it is also duplicated on SO somewhere but can't find it at the moment.
You need
library("Rfacebook") ## quotation marks optional but recommended
You need to run this command every time you start a new R session (or add it to your .Rprofile file), but you only need to install the package once (for every machine/R installation you use).

Related

ERROR: Could not find function "write.xlsx" [duplicate]

This question already has answers here:
Error: could not find function ... in R
(10 answers)
Closed 10 days ago.
I'm having real trouble running the function write.xlsx - the error "could not find function "write.xlsx"
I've already tried to:
Install the packages xlsx, readxl, writexl, XLConnect but no one of these is working.
Install Java JRE, but it's not working as well
Have you guys ever had a similar problem before?
I'm really needing to start running those flows which are properly working in other machines.
PS: I'm a beginner in the R coding
After installing the package xlsx you should also load the library in order to use the function, like this:
library(xlsx)
If you're just going to use the function one time you can call it without loading the library first like this:
xlsx::write.xlsx(data, file = "file.xlsx")
Hope this helps

Creating a custom Library Function in R [duplicate]

This question already has answers here:
Load R package from character string
(2 answers)
Closed 6 years ago.
I would like to install/load packages from a different location that is default. I dont have admin privileges so I cant access my .rprofile from the control panel.
My thought was I could just make a different library function, so I dont have to type a lib.loc statement every time i want to install/load a function. This is what i think the "liBerty" function should look like.
liBerty <- function(a) {
require(a,lib.loc="C:\\Users\\bert\\Documents\\rpackages" )
}
liBerty(tm)
The error I am getting states "there is no package 'a'.". Is there a way i can write this function to accomplish my task?
The function needs to also be modified for installing packages
install.Bertages<-function(b){
install.packages(b,lib="C:\\Users\\bert\\Documents\\rpackages")
}
liBerty<-function(a){
require(a,lib.loc="C:\\Users\\bert\\Documents\\rpackages",
character.only=TRUE )
}
install.Bertages("lubridate")
liBerty("lubridate")

How to make if statement to check whether a R package is installed or not in R [duplicate]

This question already has answers here:
Check for installed packages before running install.packages() [duplicate]
(16 answers)
Closed 6 years ago.
I am trying to make a personal R-function.
I want add if statement which can check whether essential R packages are installed.
I used exist() function but its purpose is to examine existence of an object
so it didn't work.
Is there a basic command for checking existence of a specific R-package in R?
Thx
You are looking for installed.packages() That will list all installed packages. Another option is require(thepackage) which will either load the package or return FALSE if the 'thepackage' is not available.
A way to do specifically what you asked is
"Package-Name" %in% installed.packages()
which will return TRUE or FALSE depending on whether or not "Package-Name" is installed.
However, if you're writing a script, you will usually want to use
library(Package-Name) or require(Package-Name)
If the package is installed, both will load it. If it isn't, library will throw an error, require will return FALSE and give a warning.

Make third party library available in my R package [duplicate]

This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Better explanation of when to use Imports/Depends
(4 answers)
Closed 4 years ago.
I am developing an R package that uses third party functions
available in the Bioconductor package "methyilumi"
In the code for my R package at the very beginning I import methylumi
with library(methylumi).
During the development (I use roxygen2 and devtools) everything works fine.
However, when I install the package and run my functions, I get the error:
could not find function "methylumIDAT".
Of course everything is solved if I import the package manually, but how can I make
so that methylumi is available whenever I load my own package?
Since you are using devtools, you can add
devtools::use_package("methyilumi")
in the console, and call methyilumi::methylumIDAT in the body of your function. That way, the package is automatically listed in Imports in the DESCRIPTION file.
This sections gives the instructions for several different cases:
http://r-pkgs.had.co.nz/namespace.html#imports
This is done with the NAMESPACE file and also noted in the DESCRIPTION file. There are a few ways to import a function in NAMESPACE, but the simplest is just importFrom("[PACKAGE_NAME]",[FUNCTION_NAME). Then, in DESCRIPTION, add the package name to imports.
See this very good tutorial from Friedrich Leisch.
http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf

Building a package so that it loads other packages automatically in R [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to properly use functions from other packages in a R package
load data set automatically
I've built an R package and am now testing it. It requires several packages like scatterplot3d, gdata, etc.
How can I get those packages to load automatically, when someone loads my package?
Thanks!
Edit Re Comments: I've already set imports in the Description and I've set the namespaces file. I know this works because the examples I put in work when I do R CMD Check. However, if I just load up R, type library(mypackage) it gives me an error.
Edit: Solved, I moved the packages I had in the imports section to the depends section. Thank you!

Resources