[R] setting serialization

2020-04-11 Thread Glenn Schultz via R-help
All, I have a set up as shown below.  Everything works fine but the new serialization default is 3, I would like it to serialize to version = 2.  I've tried a couple of different ways to set version and googled around but so far I've had no luck.  The package builds fine but then sets dependen

[R] using mutate to remove all white space

2020-03-01 Thread Glenn Schultz via R-help
All, This may not be the proper place to ask as the question is dplyr and removing white space using mutate.  My code is below: ```{r, echo = FALSE, message = FALSE conn <- myconnection ```{r, echo = FALSE, message=FALSE} fhlloanbalance <- tbl(conn, "fhlloan_balance_view") colnames(fhlloa

[R] S4 class slot type S4 class

2018-05-20 Thread Glenn Schultz
All, I am considering creating an S4 class whose slots (2) are both S4 classes.   Since an S4 slot can be an S3 class I figure this can be done.  However, the correct syntax of which I am unsure.  Reviewing the docs I have come to the following conclusion: SetClass('myfoo',                   s

[R] get the value of a biplane

2017-05-28 Thread Glenn Schultz
If is specify a spline basis as follows knots <- c(6, 12, 22, 30, 35) x <- c(0.0, .25, 1.0, 2.0, 3.0) SCurve <- bs(x = x, knots = knots, intercept = FALSE, Boundary.knots = c(0,3.5)) I would like to now get the spline value for new values of x.  However, when I use predict the new basis is retu

[R] modifying list in loop

2017-04-01 Thread Glenn Schultz
All, I am working on structuring a FHLMC credit risk transfer deal.  I have the deal modeled as a list of lists as shown below.  I would like to fill in the CashFlows.  The first step is simply to assign the current balance to the first position in CashFlow$BeginBal.  I am using the below func

[R] help with grep list files

2017-02-20 Thread Glenn Schultz
All, I have the following files in a directory and I would like only a list of those starting with “lld" and ending with “dat”. I used the following and it gives me the lld files list.files(path = readpath, pattern = "^lld[A-Z0-9]") to get just .dat files I tried list.files(path = readpa

[R] Zip Files

2017-01-20 Thread Glenn Schultz
All, I have a zip that was downloaded with HTTR.   I had to use HTTR because I need to login and post to the website.  The files download and by double clicking the file on my MAC the .zip file is inflated and a .txt is appears which I can then parse as needed.  However, when I use unzip either

[R] help using tryCatch

2017-01-19 Thread Glenn Schultz
All, I have  a function that I would like to return 0 or NA on unit root error but I cannot figure out how to get tryCatch to work.  I have followed the examples in the R documentation as well as some online but I am missing something.  If I added the tryCatch code I only get the error value.  

[R] getting data from a webpage

2016-12-19 Thread Glenn Schultz
All, I was getting data swap rate data from the St. Louis Fed FRED database via the FRED API.  ICE stopped reporting to FRED and now I must get the data from the ICE website.  I would like to use httr to get the data but I really don't know much about website design.  I think the form redirect

[R] using grepl in dplyr

2016-11-29 Thread Glenn Schultz
Hello All, I have a dataframe of about 1.5 million rows from this dataframe I need to filter out identifiers.  An example would be 07-07099, AD-AD0999, and AL-AL, FN-FN.  I am using grepl to identify those of interest as follows:  grepl("^[FN]|[AD]{2}", Identifier) Th

[R] using a regular expression

2016-09-11 Thread Glenn Schultz
I have a file that for basically carries three datasets of differing lengths.   To make this a single downloadable file the creator of the file as used both NUL hex00 and space hex20 to normalize the lengths. Below is the function that I am writing.  I am using sed to replace the hex characters

[R] parsing a complex file

2016-08-27 Thread Glenn Schultz
All, I have a complex file I would like to parse in R a sample is described below The header is 1:200 and the detail is 1 to 200.  I have written code to parse the file so far.  As follows: numchar <- nchar(x = data, type = "chars") start <- c(seq(1, numchar, 398)) end <- c(seq(398, numchar, 3

[R] need some help with date

2016-08-14 Thread Glenn Schultz
Here is a sample of the data that I am working with. Dates may go back as far as 1930’s. When I use as.Date() I noticed that any data < 12/31/68 returns as the new century. So I wrote this function below to be applied to the data which I dput below the function. If I use the function DateCen

[R] R Listen to a Web GUI

2016-08-10 Thread Glenn Schultz
All, I need to create a function that listens to a web GUI interface and then responds by running the needed R function. How can I do that with R? Can anyone recommend what packages I should consider. Glenn __ R-help@r-project.org mailing list -- To

[R] open a zip file

2016-08-07 Thread Glenn Schultz
All I have this code #=== Function Downloads the Factor File #' A function to download FNMA Pool Factors #' #' @importFrom httr GET #' @importFrom httr write_disk #' @importFrom httr http_status #' @importFrom httr progress #' @export FNMAPoolFactor <- function(){

[R] API key at start-up

2016-06-27 Thread Glenn Schultz
All, Is there a way to assign an API key to a value FREDAPI which is loaded and available once a R session is has started? Glenn __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do

[R] Find the first occurrence in a list

2016-03-14 Thread Glenn Schultz
All, I am looking to find the first principal payment date on structured MBS cash flow. I am testing the below to make into a function the correct index is returned. I am a little unsure. Is this the correct way to think about this problem or is there something already in R that can help? Gl

[R] Big Finance and digits

2016-02-02 Thread Glenn Schultz
All, I am modeling a FNMA credit risk transfer deal.  The size of the collateral 250 billion.  Naturally, the cashflow is quite large the cash flow is calculated and stored in a S4 object which is then converted to an array and the result is character values - converting back to numeric I lose

[R] String Matching

2016-01-29 Thread Glenn Schultz
All, I have a file named as so 313929BL4FNMA2432.rds  the user may pass either the first 9 character or the last six characters.  I need to match the remainder of the file name using either the first nine or last six.  I have read the help files for Regular Expression as used in R and I think

[R] S4 Class to Array

2015-12-16 Thread Glenn Schultz
Hello All, I would like to be able to convert and S4 class to an array but I seem to be stuck.  Reading the documentation I think I need to use setAs() and then as()  Below is a minimal example but I cannot get it to work.  So I am doing something wrong but I don't know what it is. Any insight

[R] help using SED

2015-12-05 Thread Glenn Schultz
All, I have not used SED in the past so I am continuing to read its documentation but I need some help with R Here is my SED command which works:   system("sed -i ''  '/^[\r#]/d; /AGENCY/d' /Library/Frameworks/R.framework/Versions/3.2/Resources/library/BondLab/Temp_CashFlow/blx_test.cfm") Her

[R] Some help understanding ggplot2

2015-11-28 Thread Glenn Schultz
All, I am trying to format a graph using scales and percent format but I am missing something and all my graphics books on ggplot2 are now quite far behind where ggplot2 is today.    I seem to be missing a trick but the documentation implies that percent_format() will multiply by 100 and add %

[R] Advice collating an R package

2015-11-11 Thread Glenn Schultz
Hi All, When collating a package - where does the file of constants go? I have an R package that defines 36 new classes and the AllClasses file is getting quite long.  I would like to re-organize the files the following way - which is also easier for my personal mental map of what is going on.

[R] Creating S4 class with a slot as an array

2015-10-20 Thread Glenn Schultz
Hello All, I am trying to create an S4 class with a slot that is an array.  Below is the code I tried but I have missed something.  Any suggestions are appreciated. setClass("CashFlow", representation( CashFlowArray = "array")) setMethod("initialize", signature = "CashFlow", function(.Object,

[R] R studio and git

2015-09-25 Thread Glenn Schultz
Hello all, Maybe not the right place.  I have a project that is under git version control in R studio.  I just updated to recent OSX build and now the git tab in R studio is not available.  It seems I can still use version control with source tree but it is strange that I lost git version on t

Re: [R] extracting a value from XML

2015-09-21 Thread Glenn Schultz
t;- read_xml(txt) xml_attr(xml_find_all(doc, "//observation"), "value") doc1 <- xmlParse(txt) xpathSApply(doc1, "//observation", xmlGetAttr, "value") On Mon, Sep 21, 2015 at 2:01 PM, Glenn Schultz wrote: ___

[R] extracting a value from XML

2015-09-21 Thread Glenn Schultz
Hi All, I have been trying to extract a value from XML.  I have been at it for several days off and on and I can't seem to get my head around the problem.   I basically understand the examples in R help but I cannot replicate success with the below  I tried to use xmlValue(doc, "//[[value]]")

[R] Extracting XML value

2015-09-03 Thread Glenn Schultz
All, I have made it as far as generating an api call which returns the following xml [1] "\n\n  \n\n\n\n\n" attr(,"Content-Type")               charset  "text/xml"    "UTF-8"  following DTL's presentation on the Berkley site and the package help I parsed the xml doc = xmlTreeParse(USSW10, asTe

[R] Parallel Processing

2015-08-13 Thread Glenn Schultz
Helllo All, Need some help understanding parallel processing.  I set-up DoParallel and worked perfectly.  I tried to set-up using parallel package following the book Parallel R but I get the following error: Error in checkForRemoteErrors(val) :    4 nodes produced errors; first error: 'what' mu

[R] Knit R and Book Publishing

2015-08-05 Thread Glenn Schultz
Hello All, I have finished my first R package, BondLab, and it will be available in Feb 2016.   I wrote the book and R package concurrently.  Prior, I had very little programming experience other than VBA and using others R packages.   http://www.amazon.com/Investing-Mortgage-Backed-Securities

[R] Vignette using knitr, devtools, and R markdown

2015-07-29 Thread Glenn Schultz
Hi All, I am writing a Vignette with Knitr using devtools ... actually quite awesome.   However, I would like to create a table of contents.  I have read the knitr and r markdown instructions on TOC and I can create a TOC in a markdown document but I cannot translate the command to a vignette -

[R] ggplot percent format for interest rates

2015-07-25 Thread Glenn Schultz
Hello All, The data is as follows below with ggplot command.  I would like there to be two digits to the right of the decimal on the y axis - this would be consistent with plotting interest rates.  I have not had much luck.  Any ideas are appreciated -glenn structure(list(Tenor = c(0, 1, 2,

[R] spline basis

2015-06-22 Thread Glenn Schultz
I have the following code which creates a spline function x <- c(1, 12, 24, 36, 60, 120, 200, 240, 300, 360) y <- c(.2, 8, 8, 8, 8, 8, 8, 8, 18, 50) Baseline <- cbind(x,y) Turnover <- splinefun(Baseline[,1], Baseline[,2], method = "natural") plot(Turnover(seq(1, 360, 1)), type = "l") If I chan

[R] ggplot stat_bin question

2015-06-02 Thread Glenn Schultz
All, I am using gglpot to produce combination density and histogram plots, which are actually kinda cool, everything works well and the plots look nice.  However after each plot run I receive the following message: stat_bin: binwidth defaulted to range/30. Use 'bin width = x' to adjust this.

[R] R CMD methods and ggplot2 advice

2015-05-25 Thread Glenn Schultz
Hello All, I have two packages Bond Lab and the Companion to Investing in MBS.  Bond Lab clears the check and I am working on the on.load() to copy a needed directory per Duncan Murdoch's advise to make Bond Lab CRAN-able.  The companion passes with two notes.  The output is below: I get two

[R] data for pass though OAS viewport question

2015-05-25 Thread Glenn Schultz
Attached is dput of the pass through OAS  __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented

[R] Viewport help

2015-05-24 Thread Glenn Schultz
Hello All, I have a function which outputs graphically the results of a pass-through OAS analysis.  The viewport is 2x2.  The idea is to leave a small margin at the top and enter a title with something like the following.  Bond Lab Pass Through OAS  Bond Id: f...@bond.id OAS : foo@OAS I am a

[R] Roxygen Documentation

2015-05-22 Thread Glenn Schultz
Hello R help, I am in the process of creating the companion to my book which illustrates how to call Bond Lab (my R package for MBS and fixed income).   I started with the idea of scripts and then functions calling functions.   Neither seemed very good to me.  I checked a couple of packages (Max

[R] Illustrating use of R package

2015-05-16 Thread Glenn Schultz
I have an R package Bond Lab which actually supports a book Investing in MBS using R and Open Source Computing.  The Bond Lab beta is stable.  I have also created a package companion to investing in MBS.  Both are on my Github site https://github.com/glennmschultz/ I wrote the companion as fun

Re: [R] Code works on Mac but not Windows

2015-05-11 Thread Glenn Schultz
uot;character") {standardGeneric("TermStructure")}) On May 11, 2015, at 01:54 AM, Thierry Onkelinx wrote: Dear Glenn, We need more details on the function. Please provide a commented, minimal, self-contained version of the function that reproduces the problem (as the post

[R] Code works on Mac but not Windows

2015-05-10 Thread Glenn Schultz
Hello All, Testing my code on a Windows based machine today.  There seems to be an offending line of code.  I have pasted it below.  Basically, I check to see if the user passed a fit method to TermStructure and if not then default to "ns".   The above works fine on my Mac but a windows build

[R] Package Build question for Bond Lab

2015-05-09 Thread Glenn Schultz
Hello All, I have set-up the \inst directory and now looking to the .onLoad and .onAttach for side Effects.  The Bond Lab data directories are all in \inst\BondLab.   The connection functions for BondLab are ~\users\BondLab\foo.   I would like to be able to create and copy the \inst\BondLab fo

[R] Package Build Recommendations

2015-05-06 Thread Glenn Schultz
Hi All, I have my R package built and it passes the CRAN tests.  Now, I have a question.  The file structure is not standard.  There are addition data files as follows outlined below.  Each, if you will, represents separation of concerns with respect to structured securities like MBS and REMIC

[R] Building Package Help Files

2015-04-04 Thread Glenn Schultz
Hello All, I am working on the documentation for my R package and I have a question regarding the help files.  I have noticed in some packages the developer created an alphabetical list with hyper links.  My package is for the analysis of mortgage backed securities.   So I would like to organi

[R] Package build help - thanks

2015-03-22 Thread Glenn Schultz
Hello All, I have finally addressed all the cmd issues with my package build "bondlab."  I would like to thank everyone that took the time to answer my questions.  I have the following question:  Currently the package has a non-standard directory/folder structure.  The non-standard folders are

[R] ggplot2 recycle color palette

2015-03-17 Thread Glenn Schultz
Hello All,  I have a custom color palette as illustrated below.   I have more than 8 variables.  In the case of more than 8 variables I would simply like to recycle the color.  Has anyone done this or know of a way to have to colors recycle if there are more than 8 variables. Best Regards, Gl

[R] ggplot2 help

2015-03-15 Thread Glenn Schultz
All,  I am doing something wrong but I don't see what.  When I plot in ggplot all the lines are on top of one another but the data is not.  Any help is appreciated. Thanks, Glenn  # I use this function to generate data Burnout <- function(beta1 = numeric(),                        beta

[R] bigglm connected to a database

2015-03-03 Thread Glenn Schultz
I can get bigglm working with the following code. ModelFit <- bigglm(SMM ~                      I(1-.88 * exp(-.192 * LoanAge))+                      ns(Incentive, df = 5)+                      Purpose +                     Occupancy +                     TPO +                     Servicer,      

[R] vectorize data string analysis

2015-03-02 Thread Glenn Schultz
Hello All, I have to admit that I am not that good when it comes to vectorizing a function.  I need some insight.  Is the below a case where vectorization can be accomplished to improve speed? Below the function a sample data - as you can see it is not delimited.  However, the record length i

[R] Lubridate and NameSpace

2015-02-28 Thread Glenn Schultz
  The description file is as follows:  Package: BondLab Type: Package Title: A package for the analysis of structured products Version: 0.0.0 Date: 2013-12-08 Author: Glenn Schultz, CFA Maintainer: Glenn Schultz Description: The package provides a suite of software utilities for the analysis of

[R] BondLab Package

2015-02-14 Thread Glenn Schultz
Type: Package Title: A package for the analysis of structured products Version: 0.0.0 Date: 2013-12-08 Author: Glenn Schultz, CFA Maintainer: Glenn Schultz Description: The package provides a suite of software utilities for the analysis of Mortgage and Asset Backed securities LazyLoad: yes License

[R] Package build help

2015-02-08 Thread Glenn Schultz
Hello All, I am in the final stages of building my first package "BondLab" and the check throughs the following warning.  I think this is namespace thing.  I have not done anything with the namespace at this point.  I am turning my attention to the namespace now.  Am I correct this can be a ha

[R] Package Build Suggestions

2015-01-24 Thread Glenn Schultz
Hello All, I am nearing the end of the Package BondLab.  This package is for the analysis of structured securities (MBS, REMICs, and Mortgage derivatives).  I would like to submit to CRAN but the folder structure is not standard.  Indeed, I plan to reorganize the folder structure outside the p

[R] cyclic dependency when building a package

2014-11-30 Thread Glenn Schultz
Hi All, I am working on a package BondLab for the analysis of fixed income securities. Building the package results in the following: Error in loadNamespace(package, c(which.lib.loc, lib.loc)) : cyclic namespace dependency detected when loading ‘BondLab’, already loading ‘BondLab’ It occur

[R] optimx

2014-11-29 Thread Glenn Schultz
Hello All, I need some help with optimx, mostly due to my apparent lack of imagination than optimx itself. Below is the pertinent code for which I have a question. I am fitting to the term structure of swap rates per Cox, Ingersoll, and Ross. As you can see the objective function is CIRTune.

[R] need some help with this example

2013-10-28 Thread Glenn Schultz
I have a class Details that contains information needed by FirstSet to do some calculations then a super class that returns Details and FirstSet.  The problem seems to be in FirstSet where I use the function getAnumber(id).   setClass("Details",          representation(            ID = "charact