Browse Source

LoadRData2Variable() now accepts URLs. Bumped version number.

master
Taha Ahmed 11 months ago
parent
commit
5f4f884043
  1. 6
      DESCRIPTION
  2. 20
      R/common.R
  3. 14
      man/LoadRData2Variable.Rd

6
DESCRIPTION

@ -1,8 +1,8 @@
Package: common
Type: Package
Title: chepec common
Version: 0.0.1.9001
Description: Commonly used functions and scripts.
Title: solarchemist's collection of common R functions
Version: 0.0.2
Description: solarchemist's collection of commonly-used R functions and scripts.
Authors@R: person("Taha", "Ahmed", email = "taha@chepec.se", role = c("aut", "cre"))
License: GPL-3
Encoding: UTF-8

20
R/common.R

@ -20,12 +20,24 @@ simpleCap <- function(x) {
#' Works well when the R-data file contains only ONE variable.
#' Not tested for when the R-data file contains more than one variable.
#'
#' @param FullPathToRData path to rda file
#' @param path local path to rda file (default)
#' @param url remote URL to rda file (note: requires explicitly specifying argument)
#'
#' @return an R object, you will probable want to assign it to a variable
#' @return an R object, you will probably want to assign it to a variable
#' @export
LoadRData2Variable <- function(FullPathToRData) {
return(eval(parse(text = load(FullPathToRData))))
#' @examples
#' \dontrun{
#' abscoeff <- LoadRData2Variable("/path/file.rda")
#' abscoeef <- LoadRData2Variable(url="http://public.solarchemist/data/file.rda")
#' }
LoadRData2Variable <- function(path, url = "") {
# BEWARE: this function does **not** check for all possible
# variations in the two args. Someone should really improve on that.
if (url == "") {
return(eval(parse(text = load(path))))
} else {
return(eval(parse(text = load(url(url)))))
}
}

14
man/LoadRData2Variable.Rd

@ -4,16 +4,24 @@
\alias{LoadRData2Variable}
\title{LoadRData2Variable}
\usage{
LoadRData2Variable(FullPathToRData)
LoadRData2Variable(path, url = "")
}
\arguments{
\item{FullPathToRData}{path to rda file}
\item{path}{local path to rda file (default)}
\item{url}{remote URL to rda file (note: requires explicitly specifying argument)}
}
\value{
an R object, you will probable want to assign it to a variable
an R object, you will probably want to assign it to a variable
}
\description{
This function loads R-data file into a variable instead of into the workspace.
Works well when the R-data file contains only ONE variable.
Not tested for when the R-data file contains more than one variable.
}
\examples{
\dontrun{
abscoeff <- LoadRData2Variable("/path/file.rda")
abscoeef <- LoadRData2Variable(url="http://public.solarchemist/data/file.rda")
}
}

Loading…
Cancel
Save