Software Notes

Solutions to some programming problems

Useful links/commands NodeJS to/from R async Shiny example app with dynamic number of plots
If you want to actually browse the environment of a stack frame interactively, use recover() to select a frame.
options(encoding = "UTF-8")
sudo gedit shiny-server.conf
sudo service shiny-server restart

## Installing missing packages
pkgs <- c("shiny", "dplyr", "treemap", "gridBase")
pkgs_needed <- pkgs[!(pkgs %in% installed.packages()[,"Package"])]
if(length(pkgs_needed)) install.packages(pkgs_needed)
## Run app from Github repo

rsconnect::setAccountInfo(name='urname', token='ttt', secret='xxx')
rsconnect::deployApp('C:/Projects/R/urproj') # must have app.R file

RStudio does not invoke the debugger if it looks like none of your own code is on the stack.
If you find that this is excluding an error you want to catch,
go to Tools -> Global Options and uncheck “Use debug error handler only when my code contains errors”.

use installr package to upgrade R :
- updateR(TRUE) function which updates R runtime to a new version and also its packages. (ok in Rstudio)
- The function copy.packages.between.libraries to copy files from the old library to the new one. And it doesn't copy fundamental packages as MASS, methods, utils, ...
copy.packages.between.libraries(from='C:\\Users\\user1\\Documents\\R\\win-library\\3.5', to='C:\\Users\\user1\\Documents\\R\\win-library\\3.6') =didn't work

Shiny downloadButton Disable "target='_blank" tag

Error: Failed to install 'blotter' from GitHub:
(converted from warning) incomplete final line found on 'C:\Users\me\Documents\.Rprofile'
> add empty line at end of .Rprofile

rstudio "error creating notebook: cannot open the connection"
> open a Project

need finite 'ylim' values
> In plot1, change y = range(x$VALUE) to y = range(x$VALUE, na.rm=TRUE) to remove NA missing values.

compile library source code:
> open any R-project ? Project Options : Build Tools: set the folder where the source files are
> Make (somewhere on right top side of Studio..) > "Build Binary" command > will create ZIP file > install BIN package in Studio
(or Open Project to be built from foldr > Build > tar.gz file - needs Rtools.exe installed on computer

when reloading newly compiled library: "quantmod.rdb is corrupt"
> restart R session

Error in order(order_by)[[n]] : subscript out of bounds  when we run:, trade.summary=F, silent=TRUE)
Called from: nth(x, -1L, order_by = order_by, default = default)
> nth is namespace:dplyr, called by 'last()' also namespace:dplyr in which relies on base::last() !

Error in EMA(c(NA, NA, NA, NA, NA,  :
n > number of non-NA values in column(s) 1

replace current lib with older:
see where your libs are: .libPaths()
C:\Users\user1\Documents\R\win-library\3.4 > new folder with same lib name (rename current) > copy older filesr code source > There were 12 warnings (use warnings() to see them) > warnings() > Unknown or uninitialised column: 'Date'.
>> Session > Clear Workspace... > fixed
# !diagnostics off XLSX
wb = xlsxToR("C:\\Users\\user1\\Downloads\\Ten-Symbol-Ten-Years.xlsx",keep_sheets=NULL, header=TRUE)
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed = 47s

'c:/Rtools/mingw_64/bin/g++: not found' cannot compile = wrong folder
> cat('Sys.setenv(BINPREF = "C:/Util/Rtools/mingw_$(WIN)/bin/")', file = file.path(Sys.getenv("HOME"), ".Rprofile"), sep="\n", append = TRUE)

r layout 'invalid graphics state'

Error in : figure margins too large
par("mar") #> [1] 5.1 4.1 4.1 2.1
"Error in : figure margins too large". To avoid such errors you can first check par("mar") output. You should be getting:
[1] 5.1 4.1 4.1 2.1
To change that write:
par(mar=c(1,1,1,1)) This should rectify the error. Or else you can change the values accordingly.

unable to find an inherited method for function ‘span’ for signature ‘"shiny.tag"’
> was using geosphere::span instead of htmltools::span

# RS-DBI driver: cannot allocate a new connection -- maximum of 16 connections already opened
> lapply(dbListConnections(PostgreSQL()), dbDisconnect)

cannot remove prior installation of package
> stop ALL R sessions > Sys.getenv("R_LIBS_USER") > go to pckgs folder > cmd > del /f filename

Warning: Error in [.data.frame: undefined columns selected
> bad data.frame in chart_Series or add_TA

> You could do it with a plugin like this one
similar to this

quantstrat applyStrategy 'Transactions must be added in order'
> .blotter <- new.env(); .strategy <- new.env()
object '.blotter' not found
> if (!exists('.blotter')) .blotter <- new.env()

Warning: Error in xy.coords: 'x' and 'y' lengths differ
> set Sys.envir(TZ='UTC')

blotter: Warning in getInstrument(Symbol) : instrument BCOR not found, please create it first.
> stock(symbols, currency="USD")

Error in curl::curl_fetch_memory(url, handle = handle) : Recv failure: Connection was reset
> was HTTP, replace by HTTPS

after restart R: Error in plot.xy(xy.coords(x, y), type = type, ...) : has not been called yet

rselenium not resolved from current namespace (subprocess)
> restart R


document.getElementsByName('mona')[i].onchange = fchange;
document.getElementsByName('mona')[i].addEventListener ("onchange", fchange, false);

LEAFLET Commands
JSON.stringify(table.schema, null, 4));
mlst.splice( mlst.indexOf(sel.value), 1 );
fetch(tileUrl.url, {mode: 'no-cors'}) // avoid CORS errors, but get empty tiles
alert ("Error: " + (e.stack || e)); dates!

leaflet 'TypeError: Cannot read property '_controlCorners' of undefined
> control defined before map added

Use onEachFeature for stuff you want to get done after the leaflet layers (markers/lines/polygons) have been instantiated.
> otherwise use pointToLayer

check for hasControl:
var customControl = new L.Control.Custom();
console.log(customControl._map); // undefined
console.log(customControl._map); // returns map instance

Uncaught TypeError: Cannot read property '_leaflet_id' of undefined
> expects a Leaflet control but gets something else Adding GeoJSON to Leaflet with Link Relations

EMOJI for github repos
As soon as an iframe is added to the DOM, your code will be executed:
$('html').on('DOMNodeInserted', 'iframe', function() {
alert("Fire in the hole!");
# Getting and setting CSS properties
$(this).css('background'); # get
$(this).css('background-color', '#330000'); # set

# Getting elements attributes
$(this).attr('frameborder'); # get
$(this).attr('frameborder', '0'); # set

send email from static page:

efficient JS:

google chart > CSV > Cannot read property 'getTime' of null
> last line is empty > delete

how to debug Chrome Extension Popups:
1.Click your popup button to see the webpage (the popup window itself).
2.Right-click in the window and select Inspect element
3.The Chrome Debugger window comes up with the right context, but you've already missed your breakpoints and debugger statements.
4.HERE'S THE TRICK. Click on the Console part of the debugger and type: location.reload(true) and press enter.
Now your breakpoints are hit! Great way to reload changed scripts without revisiting the Extension page.


check unresponsive Win 10 NMI_HARDWARE_FAILURE
"Remove any hardware or drivers that have been recently installed. Make sure that all memory modules are of the same type."
3 reboots > automatic repair > troubleshoot > advanced options > command prompt / startup options : 4=safe mode / startup repair > diagnosing
sfc /scannow
chkdsk /r
mdsched.exe > restart and check RAM memory
>> was the video card failing

windows 10 taskbar pop up shows but cannot click tray frozen
> find & restart Win Explorer in Task Manager, not File > Run > explorer.exe

Windows Explorer - how to disable the Preview pane
> Alt-P couple times

change default application for BAT file extension
WIN+X hotkey) > Settings > Apps > default apps > Choose default apps by file type > apps from Store only?!...
assign > ftype ...??

fix camera
> Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows Media Foundation\Platform : set EnableFrameServerMode (DWORD) = 0

disable calendar notifications windows 10
> open Settings > System > Notifications & actions > Show notifications from these apps > toggle On to Off

gpedit.msc > User Configuration > Administrative Templates > Windows Components > File Explorer
Click the Settings heading to alphabetize the list, then scroll down and find, then double-click 'Turn off the caching of thumbnails in hidden thumbs.db files' > Enable > reboot

recent files
press Windows Key+R > Enter shell:recent > hit Return

> WinExplorer > My PC > rightClick > Add Network Location > ftp://xxx

auto download images as JFIF
Open regedit > HKEY_CLASSES_ROOT > MIME > DATABASE > Content type > image/jpeg > change "extension" value to .jpg

C: drive cleanup:
> Windows download files, Log files, Dump Files, Cache files

Macrium reflect service cannot be killed
> Services > set it to Manual

1st: set Chromecast thru Google Home from Android phone, 5MHz WiFi network, Bluetooth on
♦ cast to TV without subs:
plug Chromecast in TV & power > LED white > on PC run VLC > Playback > Renderer > choose TV
    Search > ' Media Streaming Options' > All Ratings
♦ cast to TV with subtitles:
PC Chrome > Menu > Cast.. > Cast To > select source = Desktop > select 'Family Room'  see also AirFlow

how to Turn Off the Mail Background App ?
> Users can disable Mail running as a background app via Settings. To do that, press the Windows key + S hotkey.
Enter the keyword ‘background app’ in the search box.
Click Background apps to open the Settings window, Then turn off the Mail and Calendar app setting

desktop window manager high cpu windows 10
Microsoft content background task host - high CPU
> The path is: C:\Windows\System32\backgroundTaskHost.exe

Google Video Support Plugin Installer + Win installer = High CPU
> Found "Google Video Support Plugin" installed on Windows 10 laptop after checking Control Panel/Programs due to slow startup.
logs in C:\Users\guest\AppData\Local\Temp
> regedit delete for Phone Plugin 5.41.3.