Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jtilly committed Oct 27, 2015
1 parent 160b3a3 commit beab70e
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 18 deletions.
2 changes: 1 addition & 1 deletion R/read.list.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param filename The filename of the STATA log file
#' @param outdir Directory for output
#' @param RData store output in RData
#' @param tag specifies what tag to look for in the Stata log file
#' @param tag specifies what tag to look for in the STATA log file
read.list = function(filename, outdir = ".", RData = FALSE, tag = "list2csv") {

if (!file.exists(filename)) {
Expand Down
2 changes: 1 addition & 1 deletion R/read.tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param filename The filename of the STATA log file
#' @param outdir Directory for output
#' @param RData store output in RData
#' @param tag specifies what tag to look for in the Stata log file
#' @param tag specifies what tag to look for in the STATA log file
read.tab = function(filename, outdir = ".", RData = FALSE, tag = "tab2csv") {

if (!file.exists(filename)) {
Expand Down
3 changes: 1 addition & 2 deletions R/read.tabstat.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#' @param filename The filename of the STATA log file
#' @param outdir Directory for output
#' @param RData store output in RData
#' @param tag specifies what tag to look for in the Stata log file
#' @param tag specifies what tag to look for in the Stata log file
#' @param tag specifies what tag to look for in the STATA log file
read.tabstat = function(filename, outdir = ".", RData = FALSE, tag = "tabstat2csv") {

if (!file.exists(filename)) {
Expand Down
30 changes: 30 additions & 0 deletions R/statascraper.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' @name statascraper-package
#' @docType package
#' @title statascraper is an R package that extracts tables from STATA log files
#' @description This package scrapes STATA log files, looks for tables generated
#' by tab, tabstat, list, reg, and areg and then returns these tables as R
#' matrices or stores them as comma separated value files. This package can be
#' useful, when researchers (have to) use STATA to work with data sets but
#' want to use R to analyze and display results.
#' @author Jan Tilly
#' @examples
#' # In this example, we scrape the Stata log file "test.log" that was created
#' # by "stata.do"
#'
#' # point to stata log file
#' logfile = paste(system.file("example", package = "statascraper"),
#' "test.log", sep = .Platform$file.sep)
#'
#' # read tab commands
#' read.tab(filename = logfile, outdir = ".", RData = TRUE, tag = "tab2r")
#' head(load.RData("tab.RData"))
#' head(load.RData("tabsum.RData"))
#'
#' # read tabstat commands
#' read.tabstat(filename = logfile, outdir = ".", RData = TRUE, tag = "tabstat2r")
#' head(load.RData("tabstat.RData"))
#'
#' # read list commands
#' read.list(filename = logfile, outdir = ".", RData = TRUE, tag = "list2r")
#' head(load.RData("list.RData"))
NULL
10 changes: 5 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#'
#' This function removes whitespaces from the beginning and end of a string
#'
#' @param x The string to be stripped.
#' @return A string without whitespaces at the beginning and end.
#' @param x The string to be stripped
#' @return A string without whitespaces at the beginning and end
trim = function(x) {
gsub("^\\s+|\\s+$", "", x)
}
Expand All @@ -12,7 +12,7 @@ trim = function(x) {
#'
#' @param filename The path to the RData file
#' @return Returns the content of the RData file as data frame
load.RData = function(fileName){
load(fileName)
data.frame(get(ls()[ls() != "fileName"]))
load.RData = function(filename){
load(filename)
data.frame(get(ls()[ls() != "filename"]))
}
18 changes: 18 additions & 0 deletions man/load.RData.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/utils.R
\name{load.RData}
\alias{load.RData}
\title{Helper function that loads a specific file and returns the variables therein}
\usage{
load.RData(filename)
}
\arguments{
\item{filename}{The path to the RData file}
}
\value{
Returns the content of the RData file as data frame
}
\description{
Helper function that loads a specific file and returns the variables therein
}

24 changes: 24 additions & 0 deletions man/read.list.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/read.list.R
\name{read.list}
\alias{read.list}
\title{Read list}
\usage{
read.list(filename, outdir = ".", RData = FALSE, tag = "list2csv")
}
\arguments{
\item{filename}{The filename of the STATA log file}

\item{outdir}{Directory for output}

\item{RData}{store output in RData}

\item{tag}{specifies what tag to look for in the STATA log file}
}
\description{
Reads STATA tables created by \code{list x y}. For each \code{list} command found, this function will create a CSV or RData file.
For this function to work there must be a statement
\code{di "{tag} filename.csv"} preceding every \code{list} command, where
\code{{tag}} is defined in the argument to this function.
}

2 changes: 1 addition & 1 deletion man/read.reg.Rd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/readLog.R
% Please edit documentation in R/read.reg.R
\name{read.reg}
\alias{read.reg}
\title{Read regression output}
Expand Down
8 changes: 5 additions & 3 deletions man/read.tab.Rd
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/readLog.R
% Please edit documentation in R/read.tab.R
\name{read.tab}
\alias{read.tab}
\title{Read tab}
\usage{
read.tab(filename, outdir = ".", RData = FALSE)
read.tab(filename, outdir = ".", RData = FALSE, tag = "tab2csv")
}
\arguments{
\item{filename}{The filename of the STATA log file}

\item{outdir}{Directory for output}

\item{RData}{store output in RData}

\item{tag}{specifies what tag to look for in the STATA log file}
}
\description{
Reads STATA tables created by \code{tab x y} and \code{tab x, sum(y)}. For
each \code{tab} command found, this function will create a CSV or RData file.
For this function to work there must be a statement
\code{di "tab2csv filename.csv"} preceding every \code{tab} command.
\code{di "{tag} filename.csv"} preceding every \code{tab} command.
}

6 changes: 4 additions & 2 deletions man/read.tabstat.Rd
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/readLog.R
% Please edit documentation in R/read.tabstat.R
\name{read.tabstat}
\alias{read.tabstat}
\title{Read tabstat}
\usage{
read.tabstat(filename, outdir = ".", RData = FALSE)
read.tabstat(filename, outdir = ".", RData = FALSE, tag = "tabstat2csv")
}
\arguments{
\item{filename}{The filename of the STATA log file}

\item{outdir}{Directory for output}

\item{RData}{store output in RData}

\item{tag}{specifies what tag to look for in the STATA log file}
}
\description{
Reads STATA tables created by \code{tabstat y, by(x)}. For each \code{tab}
Expand Down
38 changes: 38 additions & 0 deletions man/statascraper-package.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/statascraper.R
\docType{package}
\name{statascraper-package}
\alias{statascraper-package}
\title{statascraper is an R package that extracts tables from STATA log files}
\description{
This package scrapes STATA log files, looks for tables generated
by tab, tabstat, list, reg, and areg and then returns these tables as R
matrices or stores them as comma separated value files. This package can be
useful, when researchers (have to) use STATA to work with data sets but
want to use R to analyze and display results.
}
\examples{
# In this example, we scrape the Stata log file "test.log" that was created
# by "stata.do"

# point to stata log file
logfile = paste(system.file("example", package = "statascraper"),
"test.log", sep = .Platform$file.sep)

# read tab commands
read.tab(filename = logfile, outdir = ".", RData = TRUE, tag = "tab2r")
head(load.RData("tab.RData"))
head(load.RData("tabsum.RData"))

# read tabstat commands
read.tabstat(filename = logfile, outdir = ".", RData = TRUE, tag = "tabstat2r")
head(load.RData("tabstat.RData"))

# read list commands
read.list(filename = logfile, outdir = ".", RData = TRUE, tag = "list2r")
head(load.RData("list.RData"))
}
\author{
Jan Tilly
}

6 changes: 3 additions & 3 deletions man/trim.Rd
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/readLog.R
% Please edit documentation in R/utils.R
\name{trim}
\alias{trim}
\title{Trim whitespaces from a string}
\usage{
trim(x)
}
\arguments{
\item{x}{The string to be stripped.}
\item{x}{The string to be stripped}
}
\value{
A string without whitespaces at the beginning and end.
A string without whitespaces at the beginning and end
}
\description{
This function removes whitespaces from the beginning and end of a string
Expand Down

0 comments on commit beab70e

Please sign in to comment.