So I'm trying to build a custom R package that pulls the data from MongoDB instance and then visualize graph based on that data.
My R script structure:
- authentication.R -(Authanitcate the database instance)
- information.R -(Pull the data, getting ready to plot)
- plot.R( potting the different type of graph)
This is how my information.R script one function looks like:
#' @import mongolite
#' @import dplyr
#' @import jsonify
#' @export
studentBasicInfo <- function(studentId) {
recipientsCollection <- mongo("Recipients",
db = db,
url = meteorUrl
)
studentDemography <- recipientsCollection$aggregate(sprintf('[
{ "$match": { "_id": "%s" } },
{
"$project": {
" Name": "$name",
"National ID": "$nationalId",
"Email": "$email",
"Date of Birth": "$dateOfBirth.yearMonthDay",
"Gender": "$gender"
}
}]', studentId))
studentBasicInformation <- list(
list(
"label" = "Name",
"value" = studentDemography[["Name"]]
),
list(
"label" = "National ID",
"value" = studentDemography[[National ID"]]
),
etc etc
)
)
return(studentBasicInformation)
}
so my question is Im finding hard how to pass authentication into other scripts..
This how my current authentication.R looks like..
#' @import mongolite
#' @export
authentication <- function(Username= "", Password= "", Database="") {
username <- Username
password <- Password
db <- Database
meteorUrl <- sprintf("mongodb://%s:%s@localhost:27017/", username, password)
result <- list(db = db, meteorUrl = meteorUrl)
return(result)
}
just to explain a bit more if I'm not using the package I will be using a single R script like this:
library(ggplot2)
library(dplyr)
library(mongolite)
password <- "xxxx"
username <- "yyyy"
db <- "dbInstanceName"
meteorUrl <- sprintf("mongodb://%s:%s@localhost:27017/", username, password)
studentBasicInfo <- function(studentId) {
recipientsCollection <- mongo("Recipients",
db = db,
url = meteorUrl
)
studentDemography <- recipientsCollection$aggregate(sprintf('[
{ "$match": { "_id": "%s" } },
{
"$project": {
" Name": "$name",
"National ID": "$nationalId",
"Email": "$email",
"Date of Birth": "$dateOfBirth.yearMonthDay",
"Gender": "$gender"
}
}]', studentId))
studentBasicInformation <- list(
list(
"label" = "Name",
"value" = studentDemography[["Name"]]
),
list(
"label" = "National ID",
"value" = studentDemography[[National ID"]]
),
etc etc
)
)
return(studentBasicInformation)
}
Im currently getting this error while trying to clean and rebuild the package.
Can anyone give me direction on how to solve this please .. I'm still a newbie to this R package building thingy.. thank you